在这个简单的示例中为什么StrA
在Sample()
函数中无法用“Hi World”字符串进行设置?无法在静态字段中设置变量值
string StrA { get; set; }
private void button1(object sender, EventArgs e)
{
StrA = "Hi World"; //=======> Get StrA value
}
public static string Sample()
{
MyClass MyClass1 = new MyClass();
string a = MyClass1.StrA; //==========> Can't Set StrA value with "Hi World" string ???
return (MessageBox.Show(a).ToString());
}
你能后你有课吗? “MyClass”类中的所有代码都是? – TheDude
MyClass just还包含调用Sample()的另一个事件按钮函数。 –