in C# 3, initializers were added. This is a great feature. However, one thing has me confused.
When you initialize class, you typically have to specify the member variable or property you are initializing. For example:
class C { public int i; }
public void blah() {
C c = new C() { i = 1 };
}
Array semantics have been in C# since the beginning, i think. But they don't behave like that. For example
public void foo()
{
int[] i = new int[] { 0, 1, 2, 3 };
}
All fine and good, but what about classes with array semantics?
public void bar()
{
List<int> li = new List<int>() { 0, 1, 3, 3 };
}
List is just a class, like any other (though it is a generic).
I'm trying to figure out how the compiler initializes the List member. Is this some kind of magic done behind the scenes? Or is this something related to there being an indexer defined on the class?
Thanks.