C# 从 double[] 方法返回 bool

标签 c#

如何从这个双数组方法返回 bool 值?

public static double[] GetUIPosition(string name)
    {
        if (FastUICheck.FastUICheckVisible(name, 0) == true)
        {
            UIControl control = new UIControl(Engine.Current.Memory, Engine.Current.ObjectManager.x984_UI.x0000_Controls.x10_Map[name].Value.Address);
            double[] point = new double[4];
            point[0] = control.x4D8_UIRect.Left;
            point[1] = control.x4D8_UIRect.Top;
            point[2] = control.x4D8_UIRect.Right;
            point[3] = control.x4D8_UIRect.Bottom;

            return point;

        }
        else
        {
            return false;
        }
   }

所以基本上我正在检查内存中是否存在控件并且可见,如果是,那么我想得到它的正确性。 因此,如果是,我返回一个包含 4 个点的数组,否则我想返回 false。

有没有简单的方法可以做到这一点?

最佳答案

不,bool 不可转换为 dobule[]

但是,您可以仅返回 null 并检查其是否为“false”值。

您还可以采用 TryParse 方法并返回 bool,其中 double[] 作为 out > 参数。签名为:

public static bool GetUIPosition(string name, out double[] position)

您的代码返回 null:

public static double[] GetUIPosition(string name)
{
    if (FastUICheck.FastUICheckVisible(name, 0) == true)
    {
       UIControl control = new UIControl(Engine.Current.Memory, Engine.Current.ObjectManager.x984_UI.x0000_Controls.x10_Map[name].Value.Address);
       double[] point = new double[4];
       point[0] = control.x4D8_UIRect.Left;
       point[1] = control.x4D8_UIRect.Top;
       point[2] = control.x4D8_UIRect.Right;
       point[3] = control.x4D8_UIRect.Bottom;

       return point;  
   }
   else
   {
      return null;
   }
}

类似的问题和有用的答案: How can I return multiple values from a function in C#?

关于C# 从 double[] 方法返回 bool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24297040/

相关文章:

c# - 在一个地方存储多个用户的数据

C# 提高 SIMD Sum 的性能

c# - 仅在 Win8 下 Storyboard中的内存泄漏?

c# - 使用 servicestack 创建客户端身份验证服务?

c# - C# 中缺少 Dictionary(of String, String) Item 属性

c# - 在 MVC 上使用基于 Microsoft 站点的 WordprocessingDocument 后收到消息 "MEMORY STREAM IS NOT EXPANDABLE"

c# - 如何更改 Listview 的现有 Imagelist 图像大小

c# - 为什么 DataContractJsonSerializer 和 toSource 产生不同的结果?

c# - 如何创建简单的C#二进制套接字服务器(不是WCF!)(在C#中打开和使用套接字的最简单方法?)

c# - Linq包含所有方法?