I'm fairly new to C# so this might be pretty simple actually though I have spent a couple hours searching without a solution.
I'm working with windows form and I am trying to access an object from another button-click event. The error I'm getting is "The name 'object' does not exist in the current context" when trying to access object in Button2_Click.
public void Button1_Click(object sender, EventArgs e)
{
// Prefilled with a persons info
MyClass object = new MyClass();
}
public void Button2_Click(object sender, EventArgs e)
{
// Access object
string name = object.Name;
}
So my question is how do I access an object created in another "Button_Click"?