Quote Originally Posted by George2
I read the document. There are two expansions for foreach, but I can not distinguish the differences, what are the differences?
The difference is very trivial. You only need to follow the text and compare the patterns.
In the case where the collection pattern is implemented directly you will have a GetEnumerator() method as part of the collection pattern so you can use it.
If you havn't you have to implement it using IEnumerable and therefore the GetEnumerator() is implemented by the Interface System.IEnumerable
Thats all about the differences. But I'm back to the basics.: DO EXAMPLES. Do lots of examples. If you are trying to study this language dont only use the ECMA specifications. They are great, but as they have to be very general they can confuse you. Practice is the point. Where to learn a language: Best coming to the contry where it is spoken. Why ? The daily practice. Whats the badest way to learn a language: Reading the dictionary only. I dont say. cannot be done - no but this way is full of stones in the way and heavy rocks to climb.
If you have done half a gigabyte of examples and in between reading books then I'm sure you will be able to do it.
I have seen you said: I first need to know this... bla, bla.. before I do the example. Wrong pattern. During learning Try and error is totally ok.
Its the way babys learn to go. They do their first step and fall down. stand up and do the next and so on. Thats try and error. If you want to spare time by not doing the examples and to first find out theoretically -- you will not do it.-- You get no praxis. Stop your behaviour to be a 'Theoretical' one.