c# - Instantiating a class with outside accessiblity from a method/event -


i have class game cannot made static serialization purposes. instantiate game method , have new instance accessible elsewhere in code.

if try this:

    public void btnnewgame_click(object sender, eventargs e)     {         game game = new game();     } 

the new instance unusable outside of method. there way instantiate game within method , have instance accessible elsewhere? or there workarounds? thing don't want game instantiated before button clicked.

any advice appreciated.

the singleton pattern lazy instantiation friend here.

check out this answer of mine example.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -