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

不明白的一个问题
既然可以使用静态类访问成员,为什么还要使用第二个方法,就是还要实例化才可以访问y,这么麻烦,有什么区别?
private void Page_Load(object sender, System.EventArgs e)
{
  int aa=test.x;//这里就可以直接访问x,
  test t=new test();//这里必须首先实例化才可以访问到y;
  t=y;
   
}

  public class test
  {
  public static int x=10;
  public int y=10;

  }


------解决方案--------------------
你没有定义y为静态成员
------解决方案--------------------
1L正解,LZ是新手
------解决方案--------------------
因为使用static的话就必须要在整个程序中占用一定的内存,而使用new的话就会被垃圾回收机制回收而不总是占用系统内存.所以使用new.