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.
C#
C# Quiz
Learn C# Online

or Read more about C# Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback