如何从这个双数组方法返回 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/