c# - I am unable to access any private variable inside of the same class. Anyone know why I cannot access the double "job"? -


using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace consoleapplication2 {     class test     {         private double job = 4.2; // <-- declared here         job = 5.7; // giving me "error   cs0103  name 'job' not exist in current context."       }     class program     {         static void main(string[] args)         {         }     }   } 

the double variable "job" or other variable create (ex: public or static) cannot use in class. happening in visual studio 2015. have not seen before nor know cause appreciated.

you can't change variable inside class itself. you're allowed change inside function:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace consoleapplication2 {     class test     {         private double job = 4.2; // <-- declared here          void changejob() {             job = 5.7;  // changed line inside function         }     }     class program     {         static void main(string[] args)         {         }     } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -