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

在其他类中,获取主窗口更新内容! ,

2013-02-25 
在其他类中,获取主窗口更新内容!!! 在线等,急。class form1{public int a0;test.get_a()}class test{publ

在其他类中,获取主窗口更新内容!!! 在线等,急。
class form1
{
   public int a=0;

   test.get_a();
}

class test
{
   public static void get_a()
   {
       form1 frm =new form1();
       int b=frm.a;
   }
}

为什么当form1中的a动态改变以后,在调用test.get_a()函数,得到的一直是a=0.
应该怎么改写!
[解决办法]
class test
{
   public static void get_a(form1 frm)
   {
       int b=frm.a;
   }
}
[解决办法]
class form1
{
   public int a=0;

   test.get_a(this);
}
[解决办法]
你每次调用get_a的时候都new一个form1,得到的也是这个new出来的的form里面的值,自然一直是初始值。
4,5楼正解。
或者使用属性
class form1
{
  public int a{get; set;}

}

class test
{
  form1 frm = new form1();
  int temp = frm.a;
  ...
}
[解决办法]


class form1
{
   public int a{get; set{ test.get_a(value); }}
   
}

class test
{
   private static int b
   public static void get_a(int a)
   {
       b = a;
   }
}

热点排行