Inside a class, a field declaration tells C#:
Example:
public int jerseyNumber;
Read it as:
Player objects have an accessible field named
jerseyNumberwhose type isint.
A simple class can contain:
class Player
{
public string name;
public int jerseyNumber;
public bool isAvailable;
}
The fields belong to Player objects because they are declared inside the Player class.
This:
public int jerseyNumber;
defines a field.
This:
player1.jerseyNumber = 7;
assigns a value to the field on one object.
Definition and runtime assignment are separate steps.
If the class diagram shows:
jerseyNumber : int
declare:
public int jerseyNumber;
If it shows:
isAvailable : bool
declare a compatible Boolean field.
For:
team : Team
a C# field can be:
public Team team;
That field can later refer to a Team object.
Declaring the field does not create the Team automatically.