您的位置:首页 > 编程语言 > C#

C#基础之----静态成员与非静态成员

2008-07-29 23:35 288 查看
using System;

Class Test

{

int x;

static int y;

void f(){

x = 1;//等价this.x=1

y = 1; //等价Test.y=1

}

static void g(){

x=1;//错误,不能访问this.x

y=1;//正确,等价Test.y=1

}

static void Main(){

Test t=new Test();

t.x=1;

t.y=1;//错误,不能在类的实例中访问静态成员

Test.x=1;//错误,不能按类访问非静态成员

Test.y=1;//正确

}

}

参见:asp.net中Static的用法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: