日期:2014-05-18  浏览次数:20848 次

this 怎么使用????程序为何不对?
using   System;
class   A
{
        public     int   x;
        public     void   Main()
        {
                x   =   5;
                Console.WriteLine( "the   x   value   =   {0} ",x);
                Console.WriteLine( "the   x   value   ={0} ",this.x);
               
        }
}

error   CS5001:   程序“e:\tmp\A.exe”不包含适合于入口点的静态“Main”方法

------解决方案--------------------
public static void Main()

------解决方案--------------------
LS正解
------解决方案--------------------
那就别用THIS啊
------解决方案--------------------
using System;
class A
{
public static int x;
public static void Main()
{
x = 5;
Console.WriteLine( "the x value = {0} ",x);
Console.WriteLine( "the x value ={0} ",A.x);
}
}
------解决方案--------------------
忘了x赋值
------解决方案--------------------
applethink(别腰刀的猪) ( ) 信誉:100
----------------------
正解!
------解决方案--------------------
this 是类级别的。不是函数级别的哦
------解决方案--------------------
public static void Main() 方法必须是静态的
------解决方案--------------------
this 引用的是实例变量,也可以说是非静态的变量

static 类型的变量是属于整个类的 需要用类名来引用

在静态方法中不能使用this来引用变量