I have a class Game
which cannot be made static for serialization purposes. I would like to instantiate Game
from a method and have the new instance accessible elsewhere in the code.
If I try this:
public void btnNewGame_Click(object sender, EventArgs e)
{
Game game = new Game();
}
The new instance is unusable outside of this method. Is there any way to instantiate Game
within the method and have the instance accessible elsewhere? Or are there any workarounds? The thing is that I don't want Game
to be instantiated before this button is clicked.
Any advice would be appreciated.