Classes
You can define a class by using the class
keyword followed by the name of the class written in PascalCase
.
class MyClass
{
// class stuff
}
You can define a class constructor by defining a method inside the class that matches the name of the class definition. The this
keyword is used to define instance variable assignment.
public MyClass(string name, int age)
{
this.name = name;
this.age = age;
}
You can define a static “class” variable by using the static
keyword. This is shared amongst ALL instances of the class, when it is mutated on the class it changes for all instances. These can also be assigned within the class they are defined in.
class MyClass
{
static string ClassName = "My Class";
}
You can assign a default value for a property by adding an =
equals assignment after the definition of the property.
class MyClass
{
public List<string> MyList { get; set; } = new List<string>();
}