I recently was using the BinarySearch method and I was curious about why the designers had coded the method with the following for a return value:
"Return Value
The zero-based index of item in the sorted List, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count."
(from http://msdn.microsoft.com/en-us/library/w4e7fxsh(v=vs.80).aspx)
I'm not concerned with the magnitude of the return value in my application, just whether it's positive or negative, but why did they not just design it to return the negative of the index of the next element or the negative of Count?
Thanks.