C# already provides basic types such as:
int
double
bool
stringdouble
bool
stringA class lets a programmer define a custom type that represents a concept needed by the application.
For a soccer program, useful custom types might include:
Player player1 = new Player();
Player player2 = new Player();Both objects share the same custom type.
Their field values can differ.
A class lets the program define common structure once and reuse it across many instances.
Compare:
string value1;
string value2;with:
Player player1;
Team team1;The custom types communicate more about the roles of the values.
They make the program's structure easier to relate to the system being modeled.
A UML class box named:
Playerrepresents the custom type.
An object diagram header:
player1 : Playermeans that player1 is an instance of that type.
The same type concept connects UML and C#.