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

Stack vs heap 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 stored on the stack.

C Sharp (C#)
int [1] = 10;
Drag options to blanks, or click blank then click option'
Aarray
BmyString
CmyObject
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that suggests a reference type like 'myObject'.
Confusing stack storage with heap storage.
2fill in blank
medium

Complete the code to create a reference type object stored on the heap.

C Sharp (C#)
string [1] = "hello";
Drag options to blanks, or click blank then click option'
Atext
Bcount
Cvalue
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that suggest numbers or indexes.
Thinking strings are stored on the stack.
3fill in blank
hard

Fix the error in the code to correctly allocate an object on the heap.

C Sharp (C#)
MyClass obj = [1] MyClass();
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'.
Omitting the keyword entirely.
4fill in blank
hard

Fill both blanks to create a dictionary that maps keys to values stored on the heap.

C Sharp (C#)
var dict = new Dictionary<[1], [2]>();
Drag options to blanks, or click blank then click option'
Astring
Bint
Cobject
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using value types like int for keys or values when reference types are expected.
Mixing up keys and values types.
5fill in blank
hard

Fill all three blanks to create a list of objects and add a new object to it.

C Sharp (C#)
List<[1]> list = new List<[2]>();
list.[3](new MyClass());
Drag options to blanks, or click blank then click option'
Aobject
CAdd
DAddRange
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types in the list declaration and constructor.
Using AddRange instead of Add for a single item.