I wrote a program that allow two classes to “fight”. For whatever reason C# always wins. What's wrong with VB.NET?

后端 未结 4 1885
眼角桃花
眼角桃花 2020-12-23 13:22

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)
            


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 14:03

    This happens because C# first initialize class fields, and than call base constructors. VB instead does the opposite, so when in VB you assign your value to Power, private field is not yet initialized and its value is 0.

提交回复
热议问题