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

Why understanding memory 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 variable that stores an integer value.

C Sharp (C#)
int number = [1];
Drag options to blanks, or click blank then click option'
A"10"
B10
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Assigning a boolean value instead of an integer.
2fill in blank
medium

Complete the code to allocate memory for a new object of class Person.

C Sharp (C#)
Person p = [1] Person();
Drag options to blanks, or click blank then click option'
Anew
Bcreate
Cmake
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keywords like 'create' or 'make' which are not valid in C#.
Forgetting the 'new' keyword when creating objects.
3fill in blank
hard

Fix the error in the code to correctly release unmanaged resources by implementing the Dispose pattern.

C Sharp (C#)
public void Dispose() [1]
Drag options to blanks, or click blank then click option'
A{ Console.WriteLine("Dispose called"); }
B{ return; }
C{ Dispose(true); GC.SuppressFinalize(this); }
D{ GC.SuppressFinalize(this); }
Attempts:
3 left
💡 Hint
Common Mistakes
Not calling the Dispose overload with the boolean parameter.
Only suppressing finalization without disposing resources.
4fill in blank
hard

Fill both blanks to create a dictionary that maps strings to their lengths, but only include words longer than 3 characters.

C Sharp (C#)
var lengths = new Dictionary<string, int> { { [1], [2] } };
Drag options to blanks, or click blank then click option'
A"example"
B"word"
C7
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string shorter than or equal to 3 characters.
Mismatching the string and its length.
5fill in blank
hard

Fill both blanks to create a method that returns the size of an array safely, returning 0 if the array is null.

C Sharp (C#)
public int GetSize(int[] arr) { return arr [1] [2] 0; }
Drag options to blanks, or click blank then click option'
A?
B?.Length
C??
D.Length
Attempts:
3 left
💡 Hint
Common Mistakes
Not checking for null before accessing Length.
Using incorrect operators that cause errors.