Ashwani Chaudhary

Ashwani Chaudhary

  • NA
  • 179
  • 30.5k

Confusion of access level of variables in static method.

Jul 23 2015 3:22 AM
using System;

namespace ConsoleApplication19
{
    class Program
    {
         int a = 10;
         static int b = 10;

        static void myfun()
        {
              int j = 10;

             Console.WriteLine("Hello {0}",j); // valid
             Console.WriteLine("Hello  {0}", a); //invalid
             Console.WriteLine("Hello  {0}", b); //valid
       }

     static void Main(string[] args)
     {
            myfun();
          Console.ReadKey();
    }
  }
}

 

Answers (18)