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

Value types vs reference types mental model in C Sharp (C#) - Interactive Practice

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

Complete the code to declare a value type variable.

C Sharp (C#)
int number = [1];
Drag options to blanks, or click blank then click option'
A10
B"10"
Cnull
Dnew int()
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers, which makes them strings.
Assigning null to a value type without nullable.
2fill in blank
medium

Complete the code to declare a reference type variable.

C Sharp (C#)
string text = [1];
Drag options to blanks, or click blank then click option'
A"hello"
B10
Cnull
Dnew string()
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning numbers without quotes to string variables.
Forgetting quotes around string literals.
3fill in blank
hard

Fix the error in copying value types.

C Sharp (C#)
int a = 5;
int b = [1];
// b should have the same value as a
Drag options to blanks, or click blank then click option'
Aref a
B&a
Ca
D*a
Attempts:
3 left
💡 Hint
Common Mistakes
Using reference operators like & or * which are not valid here.
Trying to assign by reference for value types.
4fill in blank
hard

Fill both blanks to copy reference types correctly.

C Sharp (C#)
class Person { public string Name; }
Person p1 = new Person();
p1.Name = "Alice";
Person p2 = [1];
p2.Name = "Bob";
Console.WriteLine(p1.Name); // Outputs [2]
Drag options to blanks, or click blank then click option'
Ap1
B"Alice"
C"Bob"
Dnew Person()
Attempts:
3 left
💡 Hint
Common Mistakes
Creating a new object for p2 instead of copying the reference.
Expecting p1.Name to stay "Alice" after changing p2.Name.
5fill in blank
hard

Fill all three blanks to create a dictionary with value types and filter by condition.

C Sharp (C#)
var scores = new Dictionary<string, int> {
    {"Alice", 90},
    {"Bob", 75},
    {"Charlie", 85}
};
var highScores = scores.Where(kv => kv.Value [1] [2]).ToDictionary(kv => kv.Key, kv => kv.Value);
Console.WriteLine(highScores[[3]]); // Outputs 90
Drag options to blanks, or click blank then click option'
A>
B80
C"Alice"
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Not quoting the dictionary key string.
Filtering with incorrect threshold.