Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You probably try to access the user_name variable from a static method. There are static and instance variables/methods. Static ones belongs to the class itself, and don't belong to instances created from that class. All instances an access the data through the class, but if you change it, it will change for all the instances -of course because it belongs to the class. This is how it looks like: class Something { private static string StaticString = "I belong to the class"; ... //constructor ... } Then, when you make a instance of this class: Something s = new Something(); You can't say string x = s.StaticString; because it belongs to the class "Something", not the instance "s". You can say however string x = Something.StaticString;</p> <p>In your example, you try to reach a instance variable, from a static method. This is the opposite of the above: the user_name is unique in each instance (say, You can have a instance with name Joe, a instance with name Robert, etc). But you try to use it on a class level. The class doens't know anything about instances created based on it. It's like when you give your dog a name, all dog should be called the same. It's not working.</p> <p>Try to use static string as user_name, so it will compile, but it won't be correct. Instead, keep the variable as a instance variable (not static), and use it in instance methods (not static). Keep in mind that you CAN use static methods and variables in instance methods, but you can't use instance variables or methnds in static methods.</p> <p>I hope that helped. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload