0
0
C Sharp (C#)programming~10 mins

Why strong typing matters in C# - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a strongly typed integer variable in C#.

C Sharp (C#)
int number = [1];
Drag options to blanks, or click blank then click option'
Atrue
B"10"
C10
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a string value like "10" to an int variable.
Using true or null which are not integers.
2fill in blank
medium

Complete the code to declare a strongly typed string variable in C#.

C Sharp (C#)
string greeting = [1];
Drag options to blanks, or click blank then click option'
A100
Bnull
Ctrue
D"Hello"
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning numbers or booleans to a string variable without quotes.
Forgetting the quotes around the text.
3fill in blank
hard

Fix the error in the code by choosing the correct type for the variable.

C Sharp (C#)
var isActive = [1];
Drag options to blanks, or click blank then click option'
Anull
Btrue
C1
D"true"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "true" as a string instead of boolean true.
Using numbers like 1 instead of boolean values.
4fill in blank
hard

Fill both blanks to create a strongly typed list of integers and add a number to it.

C Sharp (C#)
List<int> numbers = new [1]();
numbers.[2](5);
Drag options to blanks, or click blank then click option'
AList<int>
BAdd
CAddRange
DArrayList
Attempts:
3 left
💡 Hint
Common Mistakes
Using ArrayList which is not strongly typed.
Using AddRange which expects a collection, not a single item.
5fill in blank
hard

Fill all three blanks to declare a strongly typed dictionary and add a key-value pair.

C Sharp (C#)
Dictionary<[1], [2]> capitals = new Dictionary<[3], string>();
capitals.Add("France", "Paris");
Drag options to blanks, or click blank then click option'
Astring
Bint
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or bool for keys or values incorrectly.
Mismatching types between declaration and constructor.