How to use instance class in C# console app -


trying understand c# console app, static make me crazy.

in app:

static void main(string[] args) {timercallback callback...} static void tick(object state) { !here problem! } class myclass { app logic } 

problem is, in tick method need use instance of myclass, cant create new instance like:

 myclass mc = new myclass();  static void tick(){}... 

"an object reference required non-static field, method, or property". works if put myclass inside of tick, timer create new instance of myclass, , data in class dissapear.

p.s. sorry english.

you might want this:

static myclass myclass; static void main(string[] args) { myclass = new myclass(); timercallback callback... } static void tick(object state) { myclass.dosomething(); } class myclass { app logic } 

that is, create static field contain instance of myclass, , use in static methods.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -