首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

this 如何使用?程序为何不对

2012-02-10 
this 怎么使用????程序为何不对?usingSystemclassA{publicintxpublicvoidMain(){x5Console.WriteLine(

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来引用变量

热点排行