If I have a class like:
public class A
{
public A(string name)
{
Console.WriteLine("Mon");
}
}
public class B
{
private A m_a = new A("Tues");
public B()
{
m_a = new A("Wed");
}
}
I’m not on a windows machine so I can’t test the output.
What would it be, but more importantly why is it that way?
i.e why would the private var get instantiated before the constructor, or visa versa. Or would one be ignored or simply over-written?
Would Java be the same behaviour?
In both C# and Java all the initialization that is outside a constructor comes before any calls to the constructor. The assignment in the constructor would overwrite the other assignment.
For C# at least you can see the details of the language specification in section 10.11. That should answer any of the finer details of ordering, especially where inheritance is concerned.