A supplied class can contain fields with different types.
Conceptually, a Player type might include:
string name;
int jerseyNumber;
bool isAvailable;Those declarations tell you what kind of information each field is designed to hold.
Before assigning a value, identify the field's type.
Then choose a compatible value.
Suppose the supplied source contains:
string name;The field type is:
The supplied class should contain compatible field types for the model.
The UML gives you the intended state.
The C# field declaration tells you the type expected by the source.
Compare:
"7"with:
7The first is text.
The second is a numeric value.
If the field is:
int jerseyNumber;then:
7matches the intended whole-number type more directly than:
"7"Do not choose quotation marks based on how the value looks.
Choose the representation based on the field type.
For:
bool isAvailable;the Boolean literal is:
truenot:
"true"The quoted version is a string.
This difference is easy to miss because both are readable words.
C# treats them as different kinds of values.
When working in an existing project, do not guess a field's type from its name.
A field called:
numbercould be represented in several ways depending on the program.
Inspect the supplied declaration.
The code tells you the actual C# type expected by that class.
Suppose the supplied field is:
int jerseyNumber;and you accidentally try to use text.
The solution is not automatically to change the field into:
string jerseyNumber;The class design may be part of the required source.
Correct the value to match the intended type unless the task explicitly requires a class-design change.
If you assign an incompatible value, C# may report a compiler error.
Treat the message as evidence.
Ask:
Then make a focused correction.
Later programming work may convert values between representations.
At this point, prefer a value that naturally matches the supplied field type.
If the model says:
jerseyNumber = 7and the field is int, use the whole-number value.
Do not convert from text merely to make the example more complicated.
For the basic types already available from FIT:
UML / information C# type
--------------------------------
text string
whole number int
fractional number double
true/false boolThe exact supplied class controls the actual type used in the project.
Your job is to recognize that type and assign information that fits it.