Here is your answer: "a negative number, which is a bitwise addition to the index of the first element, which is greater than the value."
So, in your case, the desired value (29.6) is less than 100, which is the 3rd element in your list of arrays, and addition 3 is -3, which is the answer you received.
Here I expanded your example and created another list of arrays (list2) with some different values, then I looked for the same value as you, 29.6, now this value is 29.6 less than 100, but more than 25, and in my list 100 position 4, and her complement is -4.
So, I get the result -4, if I searched 20 in the list of arrays, I would get the answer -3.
double[] list = new double[] { 0, 0, 100, 100 }; double[] list2 = new double[] { 10, 15, 25, 100 }; int result = Array.BinarySearch(list, 29.6); int result2 = Array.BinarySearch(list2, 29.6); Response.Write("Your answer result:" + result.ToString() + "<br/>"); Response.Write("Your answer result2:" + result2.ToString());
The result of my code:
Your answer result : -3 Your answer result2: -4
Hope this helps.
Learningner
source share