The <xref:System.Collections.Generic.List%601.BinarySearch%28%600%29> method overload is then used to search for two strings that are not in the list, and the <xref:System.Collections.Generic.List%601.Insert%2A> method is used to insert them. The return value of the <xref:System.Collections.Generic.List%601.BinarySearch%2A> method is negative in each case, because the strings are not in the list. Taking the bitwise complement (the ~ operator in C# and Visual C++, `Xor` -1 in Visual Basic) of this negative number produces the index of the first element in the list that is larger than the search string, and inserting at this location preserves the sort order. The second search string is larger than any element in the list, so the insertion position is at the end of the list.
0 commit comments