c# - C#Array.BinarySearch问题

标签 c# arrays binary-search

谁能解释为什么会这样?
即。即使在位置7的数组中存在175,array.binarysearch也会返回负值吗?

请看这张图片:

Code http://www.freeimagehosting.net/uploads/555fef4560.jpg

最佳答案

您是否事先对数组进行了排序? BinarySearch希望对数组进行排序。否则,它可能会返回错误的结果。

另外,您应该检查>= 0,而不是> 0。该元素可以出现在索引0处。

关于c# - C#Array.BinarySearch问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1694312/

相关文章:

python - 在列表中执行二分搜索 - Python

c# - 如何正确使用 "this"访问表单控件?

c# - 访问文件系统 Azure 应用服务

c# - Entity Framework 附加 : object with same key exists

javascript - 为什么我的 javascript 显示值未建立?

algorithm - 在钟形值列表中找到最大值的快速算法

C# : concatenate 2 MP3 files

C 如何引用一个数组中的不同内存位置

javascript - 检查动态填充的数组中的重复对象

python - 创建特定大小的 Numpy 数组,然后以步进速率填充值