It seems like a very simple error, but I could not solve it.
I have created a Class named User in User.cs, and when I instantiate it in another .cs file, it does it, but I cannot either change its properties or reach its properties.
User user = new User();
I create a new instance like this, but then I cannot reach. For example:
user.name
The content of User class is the following:
public class User
{
public static string name;
public static int age;
public static int height;
public static int weight;
}
What is the reason and how can I solve it?
Thanks
You have created a static object, don’t instantiate the class to use it, just do
Alternativly remove the static keyword.
The word static means you don’t need to make a new insance of the class to access something so for a class with
But if you don’t use the static key word
You want to use a static value when your value does not depend on any other variables in the same class. When they do depend on varibles (or manipulations of variables) in the same class then use non static.