C# situation….i’ve set a value to a variable from another class using form1 using this…
CLASS
public int _a;
public int a
{
get
{
return _a;
}
set
{
_a = value;
}
}
Form 1
private void btnchangevalue_Click(object sender, EventArgs e)
{
class x = new class();
x.a = 1;
}
Form 2
private void btngetvalue_Click(object sender, EventArgs e)
{
class x = new class();
messagebox.show(x.a);
}
the problem is the class variable that ive set always turns to null when i’ve tried to retrieve it..
You should use a static variable
static variable is a variable that has been allocated statically, whose lifetime extends across the entire run of the program.
public static int aWhat is happening is that new variables
Are created each time
You create the form object