c# - Error Unless Declared Static -


if have class,any member in don't declare static have error if reference inside class:

an object reference required non-static field, method, or property

what doing wrong?

you error if accessing instance method static context. example

public class dog {   public void speak(){ console.writeline( "bark" ); }    public static void kickdog(){      speak(); // <- error here   } } 

instead need create instance of class

public static void kickdog() {   new dog().speak(); } 

however, mix-up might suggest misunderstanding of c# semantics , i'd recommend picking 1 of intro c# books on amazon better understanding.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -