[英]Value passing from one control to another class variable?
I have one textbox1
in form1, I have another class called ClassDemo()
, this class does not have a form. 我在form1中有一个
textbox1
,我还有一个名为ClassDemo()
类,该类没有表单。 I have one method in this class, called HelloWorld()
inside hello world I have one string val
variable. 我在此类中有一个方法,在hello world中称为
HelloWorld()
我有一个string val
变量。
I want to pass the textbox1 value to ClassDemo's variable when the HelloWorld(), method is called. 我想在调用HelloWorld()方法时将textbox1的值传递给ClassDemo的变量。
How can I do that? 我怎样才能做到这一点?
You can try multiple ways here. 您可以在这里尝试多种方式。
string
parameter inside the method declaration and then whenever you call that method, pass that string
value that you want to pass. string
参数放在方法声明中,然后每当调用该方法时,传递要传递的string
值。 string
value in global variable or Session(only if needed). string
值存储在全局变量或会话中(仅在需要时)。 This wasy, your value can flow across the application and can be accessed in any area wherever its needed. Hope this clears the idea. 希望这能清除想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.