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

     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的用法

          

posted @ 2008-07-29 23:35  liuyan  阅读(148)  评论(0编辑  收藏  举报