C#: 字段和局部变量的作用域冲突

C#把声明为类型级的变量看作字段,而把在方法中声明的变量看作局部变量

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;
}
}

此时编译器允许声明第二个变量。

posted on 2013-02-22 15:47  LilianChen  阅读(559)  评论(0编辑  收藏  举报

导航