英特尔2018校园招聘:c#编程中关于Main函数的一个问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 20:38:59
在下面的一代码(c#)中,
using System;

class A{
public int a = 1;

}

class B:A{
new int a;

public B(int b){
this.a = b;
}

public void showA(){
Console.WriteLine("the value of a is {0}",a);
}

/*public static void Main(){
B bb = new B(4);
Console.WriteLine("value of a:" + bb.a);
bb.showA();
}*/
}

class Demo
{
public static void Main()
{
B bb = new B(4);
Console.WriteLine("the value of a now is" + bb.a);
bb.showA();
}
}

Main函数所在的两个位置不同,得到的结果不同,这是为什么啊

上一位置是错误的。