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
Post a Comment