4.6.2 Collection Initializers

Jason Zhu 2021-08-11 21:39:24 +10:00
parent 9ac7f13899
commit 72c85f8a1e

@ -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