不包含适合于入口点的静态"Main"方法

来源:百度知道 编辑:UC知道 时间:2024/06/28 20:27:14
这是我写的一段小代码,用于学习this的用法,可是运行的时候却提示不包含适合于入口点的静态"Main"方法

using System;

class A
{
public int x;
public static void Main(string[] args)
{
x = 5;
Console.WriteLine("X的值是:{0}", x);
Console.WriteLine("this的X的值是:{0}", this.x);
}
}

不知道是怎么回事,求高手帮忙.

using System;

class A
{
public int x;
public void xianshi()
{
Console.WriteLine("this的X的值是:{0}", this.x);
}
public static void Main(string[] args)
{
A a = new A();
a.x = 5;
A b = new A();
b.x = 10;
Console.WriteLine("X的值是:{0}", a.x);
a.xianshi();
b.xianshi();
}
}

非静态的变量 在静态函数中必须由 new(实例化)的指针 调用。
this表示 调用它的方法。。静态函数是无法直接访问 非静态的
变量x的。。所以有问题。。