You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System.Collections.Generic/List`1.xml
+37-37Lines changed: 37 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -3489,10 +3489,10 @@ Public Function StartsWith(e As Employee) As Boolean
3489
3489
3490
3490
## Examples
3491
3491
The following example demonstrates the <xref:System.Collections.Generic.List%601.RemoveRange%2A> method and various other methods of the <xref:System.Collections.Generic.List%601> class that act on ranges. After the list has been created and modified, the <xref:System.Collections.Generic.List%601.RemoveRange%2A> method is used to remove two elements from the list, beginning at index location 2.
@@ -3713,21 +3713,21 @@ Public Function StartsWith(e As Employee) As Boolean
3713
3713
3714
3714
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.
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.
The following example demonstrates the <xref:System.Collections.Generic.List%601.Sort> method overload and the <xref:System.Collections.Generic.List%601.BinarySearch%28%600%29> method overload. A <xref:System.Collections.Generic.List%601> of strings is created and populated with four strings, in no particular order. The list is displayed, sorted, and displayed again.
3725
3725
3726
3726
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.
@@ -3803,9 +3803,9 @@ Public Function StartsWith(e As Employee) As Boolean
3803
3803
3804
3804
The <xref:System.Collections.Generic.List%601.BinarySearch%28%600%2CSystem.Collections.Generic.IComparer%7B%600%7D%29> method overload is then used to search for several strings that are not in the list, employing the alternate comparer. The <xref:System.Collections.Generic.List%601.Insert%2A> method is used to insert the strings. These two methods are located in the function named `SearchAndInsert`, along with code to take the bitwise complement (the ~ operator in C# and Visual C++, `Xor` -1 in Visual Basic) of the negative number returned by <xref:System.Collections.Generic.List%601.BinarySearch%28%600%2CSystem.Collections.Generic.IComparer%7B%600%7D%29> and use it as an index for inserting the new string.
@@ -3877,18 +3877,18 @@ Public Function StartsWith(e As Employee) As Boolean
3877
3877
## Examples
3878
3878
The following code demonstrates the <xref:System.Collections.Generic.List%601.Sort%2A> and <xref:System.Collections.Generic.List%601.Sort%2A> method overloads on a simple business object. Calling the <xref:System.Collections.Generic.List%601.Sort%2A> method results in the use of the default comparer for the Part type, and the <xref:System.Collections.Generic.List%601.Sort%2A> method is implemented using an anonymous method.
The following example demonstrates the <xref:System.Collections.Generic.List%601.Sort%28System.Comparison%7B%600%7D%29> method overload.
3884
3884
3885
3885
The example defines an alternative comparison method for strings, named `CompareDinosByLength`. This method works as follows: First, the comparands are tested for `null`, and a null reference is treated as less than a non-null. Second, the string lengths are compared, and the longer string is deemed to be greater. Third, if the lengths are equal, ordinary string comparison is used.
3886
3886
3887
3887
A <xref:System.Collections.Generic.List%601> of strings is created and populated with four strings, in no particular order. The list also includes an empty string and a null reference. The list is displayed, sorted using a <xref:System.Comparison%601> generic delegate representing the `CompareDinosByLength` method, and displayed again.
@@ -3971,9 +3971,9 @@ Public Function StartsWith(e As Employee) As Boolean
3971
3971
3972
3972
The <xref:System.Collections.Generic.List%601.BinarySearch%28System.Int32%2CSystem.Int32%2C%600%2CSystem.Collections.Generic.IComparer%7B%600%7D%29> method overload is then used to search only the range of herbivores for "Brachiosaurus". The string is not found, and the bitwise complement (the ~ operator in C# and Visual C++, `Xor` -1 in Visual Basic) of the negative number returned by the <xref:System.Collections.Generic.List%601.BinarySearch%28System.Int32%2CSystem.Int32%2C%600%2CSystem.Collections.Generic.IComparer%7B%600%7D%29> method is used as an index for inserting the new string.
The following example demonstrates the <xref:System.Collections.Generic.List%601.ToArray%2A> method and other methods of the <xref:System.Collections.Generic.List%601> class that act on ranges. At the end of the example, the <xref:System.Collections.Generic.List%601.GetRange%2A> method is used to get three items from the list, beginning with index location 2. The <xref:System.Collections.Generic.List%601.ToArray%2A> method is called on the resulting <xref:System.Collections.Generic.List%601>, creating an array of three elements. The elements of the array are displayed.
The following example demonstrates how to check the capacity and count of a <xref:System.Collections.Generic.List%601> that contains a simple business object, and illustrates using the <xref:System.Collections.Generic.List%601.TrimExcess%2A> method to remove extra capacity.
The following example demonstrates the <xref:System.Collections.Generic.List%601.TrimExcess%2A> method. Several properties and methods of the <xref:System.Collections.Generic.List%601> class are used to add, insert, and remove items from a list of strings. Then the <xref:System.Collections.Generic.List%601.TrimExcess%2A> method is used to reduce the capacity to match the count, and the <xref:System.Collections.Generic.List%601.Capacity%2A> and <xref:System.Collections.Generic.List%601.Count%2A> properties are displayed. If the unused capacity had been less than 10 percent of total capacity, the list would not have been resized. Finally, the contents of the list are cleared.
> In C# and Visual Basic, it is not necessary to create the `Predicate<string>` delegate (`Predicate(Of String)` in Visual Basic) explicitly. These languages infer the correct delegate from context and create it automatically.
0 commit comments