当前上下文中不存在名称 'binarySearchRecursive' (c#)
The name 'binarySearchRecursive' does not exist in the current context (c#)
我正在编写这个函数,但是它给了我:The name 'binarySearchRecursive' does not exist in the current context
。我不明白为什么会收到此消息,调用是在此方法本身的范围内完成的吗?还是我误解了 C# 的基本部分?
public static int binarySearchRecusive<T>(T[] a, int low, int high, T v) where T : IComparable
{
if (low < high)
{
var middle = (low + high) / 2;
if (a[middle].CompareTo(v) == 0)
return middle;
if (a[middle].CompareTo(v) < 0)
return binarySearchRecursive(a, low, middle - 1, v);
else
return binarySearchRecursive(a, middle+1, high - 1, v);
}
return -1;
}
您的函数使用这个名称:
binarySearchRecusive
如果将其更改为:
binarySearchRecursive
它会起作用。
binarySearchRecusive
中的打字错误,改为尝试 binarySearchRecursive
。
如果仍然无效,请尝试 Program.binarySearchRecursive()
我正在编写这个函数,但是它给了我:The name 'binarySearchRecursive' does not exist in the current context
。我不明白为什么会收到此消息,调用是在此方法本身的范围内完成的吗?还是我误解了 C# 的基本部分?
public static int binarySearchRecusive<T>(T[] a, int low, int high, T v) where T : IComparable
{
if (low < high)
{
var middle = (low + high) / 2;
if (a[middle].CompareTo(v) == 0)
return middle;
if (a[middle].CompareTo(v) < 0)
return binarySearchRecursive(a, low, middle - 1, v);
else
return binarySearchRecursive(a, middle+1, high - 1, v);
}
return -1;
}
您的函数使用这个名称:
binarySearchRecusive
如果将其更改为:
binarySearchRecursive
它会起作用。
binarySearchRecusive
中的打字错误,改为尝试 binarySearchRecursive
。
如果仍然无效,请尝试 Program.binarySearchRecursive()