A Generic C# 3.0 Collection Initialization Adapter
February 29th, 2008C# 3.0 comes with this new language feature called Collection Initializaton. It’s more or less syntactical sugar that simplifies the way you initialize collections.
Where you pre 3.0 would initialize a list of integers like this:
List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3);
You now can do this:
List<int> list = new List<int>() {1, 2, 3};
Now, this is somewhat beautified, but it does exactly the same as in the first example. The compiler parses the code and calls the Add method, implemented by List<int>, once for every integer in the initialization list.
Now, wouldn’t this be nice to do on your own proprietary collections? Read the rest of this entry »












