I wrote a program that allow two classes to \"fight\". For whatever reason C# always wins. What\'s wrong with VB.NET ?
static void Main(string[] args)
Promoting my comments to an answer:
Me:
Try writing each "power" to the console as well
Prankster:
C#: 100 VB.NET: 0
Me:
As I suspected. Looks like VB.Net is calling the Base constructor before the inherited constructor, and therefore VB's desiredPower variable is still 0, whereas C# does it in reverse (remember, literal initialization happens at the end of the constructor).
Update:
I wanted to find some documentation on the behavior (otherwise you're looking at behavior that might change out from under you with any new .Net release). From the link:
The constructor of the derived class implicitly calls the constructor for the base class
and
Base class objects are always constructed before any deriving class. Thus the constructor for the base class is executed before the constructor of the derived class.
Those are on the same page and would seem to be mutually exclusive, but I take it to mean the derived class constructor is invoked first, but it is assumed to itself invoke the base constructor before doing any other work. Therefore it's not constructor order that important, but the manner in which literals are initialized.
I also found this reference, which clearly says that the order is derived instance fields, then base constructor, then derived constructor.