CSharp - What is the output: Fields elements?

Question

What is the output of the following code?

using System;
class MainClass
{
   static int x;
   public static void Main(string[] args)
   {
      Console.WriteLine (x); 
   }
}


Click to view the answer

0

Note

The code outputs 0, because fields are implicitly assigned a default value

Fields elements are automatically initialized with the default values for their type.

Related Quiz