c# - An object refference is requied for non-static field, method or property -


i following error when compiling application:

an object refference requied non-static field, method or property

this code:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace consoleopener {     class program     {         public static int casse;         random rnd = new random();         public static int openit(int casse)         {            int32 skin = 0;            if (casse==1)            {                skin = rnd.next(1, 3);            }             return skin;         }           public static void main(string[] args)         {             console.writeline("choose 1 of cases:");             console.writeline("1. test case");             int casse = console.read();             openit(casse);         }     } } 

how can solve this? edit-- please... wouldn't write if find answer. says (set static static

you can solve problem declaring random rnd; parameter static:

static random rnd = new random();   // declaring rnd static public static int openit(int casse) {    int32 skin = 0;    if (casse==1)    {       skin = rnd.next(1, 3);    }    return skin; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -