A class operation can promise a value back to its caller. The return type describes what kind of result a player query supplies.
This complete Player class reports its current turn count without changing it.
If the underlying C# feature is unfamiliar, use the lesson below while reading this example.
public class Player
{
public int numberOfTurns;
public int GetNumberOfTurns()
{
return numberOfTurns;
}
}Define a Player with a stored integer turn count
Offer a public operation named GetNumberOfTurns
The operation accepts no inputs
It returns the current turn count as an integer
It does not change that countThese words describe the class contract, not a sequence of runtime actions. Identify the types, stored members, operation inputs and results, and relationships before choosing compartments and connectors.
Player box.+numberOfTurns : int in the attributes compartment.+GetNumberOfTurns() : int in the operations compartment. Preserve the empty parentheses and the result type after them.Compare this reference with the diagram you built in Violet. Layout may differ; the source meaning, labels, and relevant connections should agree.
An instance with count 2 can return 2; another with count 0 can return 0. Both follow the same operation declaration.