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:
string
A compatible text value can look like:
"Jordan"
Now consider:
int jerseyNumber;
The field type is:
int
A compatible whole-number value can look like:
7
For:
bool isAvailable;
a compatible Boolean value is:
true
or:
false
A UML object diagram might show:
player1 : Player
-------------------------
name = "Jordan"
jerseyNumber = 7
isAvailable = true
The values suggest different kinds of data:
"Jordan" → text
7 → whole number
true → Boolean
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:
7
The first is text.
The second is a numeric value.
If the field is:
int jerseyNumber;
then:
7
matches 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:
true
not:
"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:
number
could 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 = 7
and 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 bool
The exact supplied class controls the actual type used in the project.
Your job is to recognize that type and assign information that fits it.