Let's say I have this class with a constructor that fills the internal list with two entries:
class MyClass
{
IList<int> someList;
public MyClass()
{
someList = new List<int>();
someList.Add(2);
someList.Add(4);
... // do some other stuff
}
}
Now let's say I have several constructors which all do the same with the internal list (but differ in other aspects).
I would like to know if I can outsource the generation and filling of the list directly to the field, like this:
class MyClass
{
IList<int> someList = new List<int>(); someList.Add(2); someList.Add(4);
// Does not compile.
public MyClass()
{
... // do some other stuff
}
}
Is it possible to call several commands in the field definition, and if yes, how?