Accessing generic enumerator on arrays

Is it possible to access the generic enumerator on an array instance? I.e. what goes in place of the question marks to make this work:

PublicClass MyClass
Implements IEnumerable(Of X)'Class X is declared elsewhere

PrivateFunction GetEnumerator()As IEnumerator(Of X)Implements IEnumerable(Of X).GetEnumerator
Return _stuff.?
EndFunction

PrivateFunction GetEnumerator1()As System.Collections.IEnumeratorImplements IEnumerable.GetEnumerator
Return _stuff.GetEnumerator
EndFunction

Private _stuff()As X = {...}

EndClass

Thanks!

Ian Horwill

[2083 byte] By [IanHorwill] at [2007-12-24]
# 1

I don't know if theres any way to do this other than:

Public Function GetEnumerator() As IEnumerator(Of x) Implements IEnumerable(Of x).GetEnumerator
Dim lst As New List(Of x)
For Each itm As x In Me._stuff
lst.Add(itm)
Next
Return lst.GetEnumerator

End Function

I know that's not great looking, but it will work.

rkimble at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Arrays are directly convertible to IEnumerable(Of TypeOfArray). So the following code will work.

Public Function GetEnumerator() As IEnumerator(Of X)

Return DirectCast(_stuff, IEnumerable(Of X)).GetEnumerator()

End Function

JaredParsonsMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...