Kevins의 대답은 올바른하고 이 게으름으로 열거을 변경할 수 있습니다. Trodek 응답을 사용하는 경우 다음 예외가 throw됩니다.
Cannot implicitly convert type `System.Collections.Generic.List<SomeClass<T>>.Enumerator' to `System.Collections.Generic.IEnumerator<T>'(CS0029)
그럼에도 불구하고 댓글을 달고 싶습니다. 수익률 반환을 사용하면 다른 값을 반환하는 상태 시스템이 생성됩니다. yield 결과를 사용하여 중첩 된 데이터 구조 (예 : 나무)를 사용하려는 경우 모든 하위 구조마다 다른 상태 시스템이 작성되므로 훨씬 많은 메모리가 할당됩니다.
글쎄, 그건 내 두 센트 야! 당신이
MyNamespace.MyClass<T>' does not implement interface
member 'System.Collections.IEnumerable.GetEnumerator()'.
'WindowsFormsApplication1.SomeClass<T>.GetEnumerator()' cannot implement
'System.Collections.IEnumerable.GetEnumerator()' because it does not have
the matching return type of 'System.Collections.IEnumerator'.
당신이 필요로하는 메시지를받은 경우는 허용 대답에 추가 할 객체 SomeClass에서 객체 T를 얻을 수있는 방법이 가정
왜'MyList'는'T' 대신'SomeClass'의 모음입니까? –
jasonh
사실 트리 컬렉션을 구현 중이므로 실제로 myList는 자식 컬렉션입니다. 나는 그것을 언급 했어야했다 ... –