C: scope conflict between of variable field and local variable

  • 2020-05-09 19:05:11
  • OfStack

C# treats variables declared at the type level as fields, and variables declared in methods as local variables.


using System;
namespace ConsoleApplication10
{
class Program
{
static int j = 20;
public static void Main(string[] args)
{
int j = 30;
Console.WriteLine("In the Main()" + j);
Console.WriteLine(Program.j);
Console.ReadLine(); 
return;
}
}

The compiler allows you to declare a second variable at this point.


Related articles: