Allow internal struct enumerators and GetEnumerator to be used by foreach loop. #952
Replies: 3 comments
-
Changing this behavior might break the meaning of existing code unless the compiler favors implementations of |
Beta Was this translation helpful? Give feedback.
-
@HaloFour with explicit interface implementations? |
Beta Was this translation helpful? Give feedback.
-
Yes, although the CLR is not limited to how C# does explicit implementations. For example, in VB.NET you're allowed to both rename the implemented method as well as change the accessibility to whatever you want: Public Class Foo
Implements IEnumerable(Of Integer)
Private Function Bar() As IEnumerator(Of Integer) _
Implements IEnumerable(Of Integer).GetEnumerator
Return Nothing
End Function
Friend Function Baz() As IEnumerator _
Implements IEnumerable.GetEnumerator
Return Nothing
End Function
End Class In either case the C# compiler currently favors |
Beta Was this translation helpful? Give feedback.
-
I don't see why following gives error. apparently foreach can not see the method.
foreach will only see this method if its public. but why is this requirement? my type is public, but I want the struct enumerator to be internal. I know workaround for this, but I'm just being curios.
I don't think its CLR thing again, it simply can be understood by compiler, please allow this.
Beta Was this translation helpful? Give feedback.
All reactions