The IEnumerable(Of T) interface exists so that clients have a well-defined way to obtain
an enumerator on the collection. The following code defines the IEnumerable(Of T) and
IEnumerable interfaces:
Public Interface IEnumerable(Of T)
Inherits IEnumerable
Overloads Function GetEnumerator() As IEnumerator(Of T)
End Interface
Public Interface IEnumerable
Function GetEnumerator() As IEnumerator
End Interface
Since both interfaces implement GetEnumerator(), any collection that implements
IEnumerable(Of T) needs to implement one of the GetEnumerator methods explicitly. It makes
the most sense to implement the type-less IEnumerable.GetEnumerator method explicitly. The
IEnumerator(Of T) and IEnumerator interfaces are shown here:
Public Interface IEnumerator(Of T)
Inherits IEnumerator
Inherits IDisposable
Overloads ReadOnly Property Current() As T
End Interface
Public Interface IEnumerator
ReadOnly Property Current() As Object
Function MoveNext() As Boolean
Sub Reset()
End Interface
Again, the two interfaces implement a member that has the same signature, which, in
this case, is the Current property. When implementing IEnumerator(Of T), you should implement
IEnumerator.Current explicitly. Finally, notice that IEnumerator(Of T) implements the
IDisposable interface.
Pages:
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354