Will the following code compile:
 
   class Program 
   { 
      private static int i; 
      static Program(int a)
      { 
          this.i = a; 
          Console.WriteLine("In static constructor"); 
      } 
      static void Main(string[] args) { } 
  }
 
Explanation
There are two errors in the code:
1) The static constructor of the class (type constructor) must not contain parameters.
2) The keyword 'this' can not be used in static properties, methods, or static initializer field.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты