Professional Documents
Culture Documents
Classes and Objects
Classes and Objects
Classes and Objects
2024, 7:55 PM
Cheatsheets / Learn C#
C# Classes
about:srcdoc Page 1 of 11
19.01.2024, 7:55 PM
C# Constructor
about:srcdoc Page 2 of 11
19.01.2024, 7:55 PM
C# Parameterless Constructor
C# Access Modifiers
about:srcdoc Page 3 of 11
19.01.2024, 7:55 PM
{
return FormalGreeting().ToUpper();
}
about:srcdoc Page 4 of 11
19.01.2024, 7:55 PM
C# Field
about:srcdoc Page 5 of 11
19.01.2024, 7:55 PM
C# this Keyword
In C#, the this keyword refers to the current // We can use the this keyword to refer
instance of a class.
to the current class’s members hidden
by similar names:
public NationalPark(int area, string
state)
{
this.area = area;
this.state = state;
}
about:srcdoc Page 6 of 11
19.01.2024, 7:55 PM
C# Members
C# Dot Notation
// Prints 5
Console.WriteLine(greeting.Length);
// Returns 8
Math.Min(8, 920);
about:srcdoc Page 7 of 11
19.01.2024, 7:55 PM
C# Class Instance
about:srcdoc Page 8 of 11
19.01.2024, 7:55 PM
C# Property
// Prints "Louie"
Console.WriteLine(f.FirstName);
}
about:srcdoc Page 9 of 11
19.01.2024, 7:55 PM
C# Auto-Implemented Property
about:srcdoc Page 10 of 11
19.01.2024, 7:55 PM
C# Static Constructor
C# Static Class
In C#, a static class cannot be instantiated. Its //Two examples of static classes
members are accessed by the class name.
calling static methods:
This is useful when you want a class that
provides a set of tools, but doesn’t need to
maintain any internal data. Math.Min(23, 97);
Math is a commonly-used static class.
Console.WriteLine("Let's Go!");
Print Share
about:srcdoc Page 11 of 11