IEnumerable<T> provides two GetEnumerator methods - what is the difference between them?
问题 When I emplement IEnumerable<T> interface I see two GetEnumerator methods: one returning IEnumerator and other IEnumerator<T> . When would I use one or another? 回答1: If you are implementing the IEnumerable<T> generic interface, you will pretty much always have to use the generic GetEnumerator method - unless you cast your object explicitly to (non-generic) IEnumerable. The reason is backwards compatability with .NET 1.0/1.1 which didn't support generics. 回答2: You usually implement both. One