4.6.2 Collection Initializers
parent
9ac7f13899
commit
72c85f8a1e
16
chap04.md
16
chap04.md
@ -408,6 +408,22 @@ using(var enumerator = "beer".GetEnumerator())
|
||||
|
||||
### 4.6.2 Collection Initializers
|
||||
|
||||
*Instantiation* and *population* of an enumerable object can be done in single step
|
||||
|
||||
e.g. compiler translation of instantiation and population of enumerable object
|
||||
```csharp
|
||||
using System.Collections.Generic;
|
||||
...
|
||||
List<int> list = new List<int> {1,2,3};
|
||||
|
||||
// which is translated into
|
||||
List<int> list = new List<int>();
|
||||
list.Add(1);
|
||||
list.Add(2);
|
||||
```
|
||||
|
||||
The translation (by compiler) requires enumerable object implements the `System.Collections.IEnumerable` interface, which has `Add` method.
|
||||
|
||||
### 4.6.3 Iterators
|
||||
|
||||
### 4.6.4 Iterator Semantics
|
||||
|
Loading…
x
Reference in New Issue
Block a user