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

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -