8000 Try .NET updates -- system.collections.generic.list-1.sort (#3462) · CAndRyan/dotnet-api-docs@0a76fc2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a76fc2

Browse files
WilliamAntonRohmmairaw
authored andcommitted
Try .NET updates -- system.collections.generic.list-1.sort (dotnet#3462)
* updating for Try .NET * addressing review comment
1 parent e91d715 commit 0a76fc2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

xml/System.Collections.Generic/List`1.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,9 +3618,12 @@ Public Function StartsWith(e As Employee) As Boolean
36183618
36193619
36203620
## Examples
3621+
3622+
[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]
3623+
36213624
The following example adds some names to a `List<String>` object, displays the list in unsorted order, calls the <xref:System.Collections.Generic.List%601.Sort%2A> method, and then displays the sorted list.
36223625
3623-
[!code-csharp[System.Collections.Generic.List.Sort#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.sort/cs/Sort1.cs#2)]
3626+
[!code-csharp-interactive[System.Collections.Generic.List.Sort#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.sort/cs/Sort1.cs#2)]
36243627
[!code-vb[System.Collections.Generic.List.Sort#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.list.sort/vb/Sort1.vb#2)]
36253628
36263629
The following code demonstrates the <xref:System.Collections.Generic.List%601.Sort> and <xref:System.Collections.Generic.List%601.Sort%28System.Comparison%7B%600%7D%29> method overloads on a simple business object. Calling the <xref:System.Collections.Generic.List%601.Sort> method results in the use of the default comparer for the Part type, and the <xref:System.Collections.Generic.List%601.Sort%28System.Comparison%7B%600%7D%29> method is implemented by using an anonymous method.
@@ -3633,7 +3636,7 @@ Public Function StartsWith(e As Employee) As Boolean
36333636
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.
36343637
36353638
[!code-cpp[List\`1_SortSearch#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_SortSearch/cpp/source.cpp#1)]
3636-
[!code-csharp[List\`1_SortSearch#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_SortSearch/cs/source.cs#1)]
3639+
[!code-csharp-interactive[List\`1_SortSearch#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_SortSearch/cs/source.cs#1)]
36373640
[!code-vb[List\`1_SortSearch#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_SortSearch/vb/source.vb#1)]
36383641
36393642
]]></format>

0 commit comments

Comments
 (0)
0