Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions xml/System.Collections.Generic/List`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following example demonstrates how to add, remove, and insert a simple business object in a <xref:System.Collections.Generic.List%601>.

[!code-csharp[System.Collections.Generic.List.AddRemoveInsert#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.addremoveinsert/cs/program.cs#1)]
Expand All @@ -127,7 +130,7 @@
Finally, the <xref:System.Collections.Generic.List%601.Clear%2A> method is used to remove all items from the list, and the <xref:System.Collections.Generic.List%601.Capacity%2A> and <xref:System.Collections.Generic.List%601.Count%2A> properties are displayed.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -201,12 +204,15 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following example demonstrates the parameterless constructor of the <xref:System.Collections.Generic.List%601> generic class. The parameterless constructor creates a list with the default capacity, as demonstrated by displaying the <xref:System.Collections.Generic.List%601.Capacity%2A> property.

The example adds, inserts, and removes items, showing how the capacity changes as these methods are used.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -387,6 +393,9 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following example demonstrates how to add, remove, and insert a simple business object in a <xref:System.Collections.Generic.List%601>.

[!code-csharp[System.Collections.Generic.List.AddRemoveInsert#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.addremoveinsert/cs/program.cs#1)]
Expand All @@ -398,7 +407,7 @@
Other properties and methods are used to search for, insert, and remove elements from the list, and finally to clear the list.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -840,8 +849,11 @@
Retrieving the value of this property is an O(1) operation; setting the property is an O(*n*) operation, where *n* is the new capacity.



## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

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.

[!code-csharp[System.Collections.Generic.List.CapacityCount#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.capacitycount/cs/program.cs#1)]
Expand All @@ -852,7 +864,7 @@
The <xref:System.Collections.Generic.List%601.Capacity%2A> property is displayed again after the <xref:System.Collections.Generic.List%601.TrimExcess%2A> method is used to reduce the capacity to match the count. Finally, the <xref:System.Collections.Generic.List%601.Clear%2A> method is used to remove all items from the list, and the <xref:System.Collections.Generic.List%601.Capacity%2A> and <xref:System.Collections.Generic.List%601.Count%2A> properties are displayed again.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -913,10 +925,13 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)]

The following example demonstrates the <xref:System.Collections.Generic.List%601.Clear%2A> method and various other properties and methods of the <xref:System.Collections.Generic.List%601> generic class. The <xref:System.Collections.Generic.List%601.Clear%2A> method is used at the end of the program, to remove all items from the list, and the <xref:System.Collections.Generic.List%601.Capacity%2A> and <xref:System.Collections.Generic.List%601.Count%2A> properties are then displayed.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -1335,6 +1350,9 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

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.

[!code-csharp[System.Collections.Generic.List.CapacityCount#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.capacitycount/cs/program.cs#1)]
Expand All @@ -1343,7 +1361,7 @@
The following example shows the value of the <xref:System.Collections.Generic.List%601.Count%2A> property at various points in the life of a list. After the list has been created and populated and its elements displayed, the <xref:System.Collections.Generic.List%601.Capacity%2A> and <xref:System.Collections.Generic.List%601.Count%2A> properties are displayed. These properties are displayed again after the <xref:System.Collections.Generic.List%601.TrimExcess%2A> method has been called, and again after the contents of the list are cleared.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -2707,6 +2725,9 @@ Public Function StartsWith(e As Employee) As Boolean


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following example demonstrates how to add, remove, and insert a simple business object in a <xref:System.Collections.Generic.List%601>.

[!code-csharp[System.Collections.Generic.List.AddRemoveInsert#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.addremoveinsert/cs/program.cs#1)]
Expand All @@ -2716,7 +2737,7 @@ Public Function StartsWith(e As Employee) As Boolean
The following example demonstrates the <xref:System.Collections.Generic.List%601.Insert%2A> method, along with various other properties and methods of the <xref:System.Collections.Generic.List%601> generic class. After the list is created, elements are added. The <xref:System.Collections.Generic.List%601.Insert%2A> method is used to insert an item into the middle of the list. The item inserted is a duplicate, which is later removed using the <xref:System.Collections.Generic.List%601.Remove%2A> method.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -3163,6 +3184,9 @@ Public Function StartsWith(e As Employee) As Boolean


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following example demonstrates how to add, remove, and insert a simple business object in a <xref:System.Collections.Generic.List%601>.

[!code-csharp[System.Collections.Generic.List.AddRemoveInsert#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.addremoveinsert/cs/program.cs#1)]
Expand All @@ -3172,7 +3196,7 @@ Public Function StartsWith(e As Employee) As Boolean
The following example demonstrates <xref:System.Collections.Generic.List%601.Remove%2A> method. Several properties and methods of the <xref:System.Collections.Generic.List%601> generic class are used to add, insert, and search the list. After these operations, the list contains a duplicate. The <xref:System.Collections.Generic.List%601.Remove%2A> method is used to remove the first instance of the duplicate item, and the contents are displayed. The <xref:System.Collections.Generic.List%601.Remove%2A> method always removes the first instance it encounters.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -4808,6 +4832,9 @@ finally


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

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.

[!code-csharp[System.Collections.Generic.List.CapacityCount#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.list.capacitycount/cs/program.cs#1)]
Expand All @@ -4816,7 +4843,7 @@ finally
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.

[!code-cpp[List\`1_Class#1](~/samples/snippets/cpp/VS_Snippets_CLR/List`1_Class/cpp/source.cpp#1)]
[!code-csharp[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-csharp-interactive[List\`1_Class#1](~/samples/snippets/csharp/VS_Snippets_CLR/List`1_Class/cs/source.cs#1)]
[!code-vb[List\`1_Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/List`1_Class/vb/source.vb#1)]
[!code-fsharp[List\`1_Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR/List`1_Class/fs/listclass.fs#1)]

Expand Down Expand Up @@ -4897,4 +4924,4 @@ finally
</Docs>
</Member>
</Members>
</Type>
</Type>