如何访问不同类的值。 [英] How to access the value of different classes.
本文介绍了如何访问不同类的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个课程如下。
i have 3 classes as follows.
class a
{
string access;
public void setaccess(string c)
{
this.access = c;
}
public string getaccess()
{
return this.access;
}
}
class b: a
{
setaccess("test");
}
//Form class
class c
{
a aa = new a();
string bb = aa.getaccess();
messagebox.show(bb);
}
我希望类b更新类a中变量access的值,并更新要在类c中显示的值。现在,当我运行应用程序时,消息框为空。谁能帮帮我吗。我无法弄清楚我做错了什么。
i want the class b to update the value of variable "access" in class a and the updated value to be shown in class c. Right now when i run the application the messagebox is empty. Can anyone please help me. I can not figure out what am i doing wrong.
推荐答案
试试这个
Try this
b aa = new b();
string bb = aa.getaccess();
messagebox.show(bb);
试试这个
try this
public class a
{
string access;
public void setaccess(string c)
{
this.access = c;
}
public string getaccess()
{
return this.access;
}
}
public class b : a
{
public b()
: base()
{
setaccess("updated");
}
}
//Form class
public class c
{
public void test()
{
b aa = new b();
string bb = aa.getaccess();
messagebox.show(bb);
}
}
试用此代码
Try This Code
// Create b class object because your are setting values of class a var in b class
public class c
{
public void test()
{
b aa = new b();
string bb = aa.getaccess();
messagebox.show(bb);
}
}
这篇关于如何访问不同类的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文