|
67 | 67 | The following example demonstrates how to implement the <xref:System.Collections.Generic.IEnumerable%601> interface and how to use that implementation to create a LINQ query. When you implement <xref:System.Collections.Generic.IEnumerable%601>, you must also implement <xref:System.Collections.Generic.IEnumerator%601> or, for C# only, you can use the [yield](/dotnet/csharp/language-reference/keywords/yield) keyword. Implementing <xref:System.Collections.Generic.IEnumerator%601> also requires <xref:System.IDisposable> to be implemented, which you will see in this example. |
68 | 68 | |
69 | 69 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.ienumerableex/cs/program.cs" id="Snippet1"::: |
70 | | - :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.ienumerableex/vb/module1.vb" id="Snippet1"::: |
71 | | - |
72 | | - For another C# example that demonstrates how to implement the <xref:System.Collections.Generic.IEnumerable%601> interface, see the [Generics Sample](https://code.msdn.microsoft.com/Generics-Sample-C-9b41a192/sourcecode?fileId=46476&pathId=1364935593). This sample uses the `yield` keyword instead of implementing <xref:System.Collections.Generic.IEnumerator%601>. |
| 70 | + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.ienumerableex/vb/module1.vb" id="Snippet1"::: |
73 | 71 | |
74 | 72 | ]]></format> |
75 | 73 | </remarks> |
|
81 | 79 | <related type="Article" href="/dotnet/visual-basic/programming-guide/language-features/control-flow/walkthrough-implementing-ienumerable-of-t">Walkthrough: Implementing IEnumerable(Of T) in Visual Basic</related> |
82 | 80 | <related type="Article" href="/dotnet/csharp/programming-guide/concepts/iterators">Iterators (C#)</related> |
83 | 81 | <related type="Article" href="/dotnet/visual-basic/programming-guide/concepts/iterators">Iterators (Visual Basic)</related> |
84 | | - <related type="ExternalDocumentation" href="https://code.msdn.microsoft.com/Generics-Sample-C-9b41a192/sourcecode?fileId=46476&pathId=1364935593">Generics Sample</related> |
85 | 82 | </Docs> |
86 | 83 | <Members> |
87 | 84 | <Member MemberName="GetEnumerator"> |
|
140 | 137 | |
141 | 138 | An enumerator does not have exclusive access to the collection so an enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and you may get unexpected results. Also, enumerating a collection is not a thread-safe procedure. To guarantee thread-safety, you should lock the collection during enumerator or implement synchronization on the collection. |
142 | 139 | |
143 | | - Default implementations of collections in the <xref:System.Collections.Generic?displayProperty=nameWithType> namespace aren't synchronized. |
144 | | - |
145 | | - |
| 140 | + Default implementations of collections in the <xref:System.Collections.Generic?displayProperty=nameWithType> namespace aren't synchronized. |
146 | 141 | |
147 | 142 | ## Examples |
148 | 143 | The following example demonstrates how to implement the <xref:System.Collections.Generic.IEnumerable%601> interface and uses that implementation to create a LINQ query. When you implement <xref:System.Collections.Generic.IEnumerable%601>, you must also implement <xref:System.Collections.Generic.IEnumerator%601> or, for C# only, you can use the [yield](/dotnet/csharp/language-reference/keywords/yield) keyword. Implementing <xref:System.Collections.Generic.IEnumerator%601> also requires <xref:System.IDisposable> to be implemented, which you will see in this example. |
149 | 144 | |
150 | 145 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.generic.ienumerableex/cs/program.cs" id="Snippet1"::: |
151 | | - :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.ienumerableex/vb/module1.vb" id="Snippet1"::: |
152 | | - |
153 | | - For another C# example that demonstrates how to implement the <xref:System.Collections.Generic.IEnumerable%601> interface, see the [Generics Sample](https://code.msdn.microsoft.com/Generics-Sample-C-9b41a192/sourcecode?fileId=46476&pathId=1364935593). This sample uses of the `yield` keyword instead of implementing <xref:System.Collections.Generic.IEnumerator%601>. |
| 146 | + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.ienumerableex/vb/module1.vb" id="Snippet1"::: |
154 | 147 | |
155 | 148 | ]]></format> |
156 | 149 | </remarks> |
|
0 commit comments