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

Value type vs reference type performance 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 struct.

C Sharp (C#)
public struct [1] { public int Number; }
Drag options to blanks, or click blank then click option'
AMyInterface
BMyEnum
CMyClass
DMyStruct
Attempts:
3 left
💡 Hint
Common Mistakes
Using class instead of struct to declare a value type.
2fill in blank
medium

Complete the code to create a reference type instance.

C Sharp (C#)
MyClass obj = new [1]();
Drag options to blanks, or click blank then click option'
AMyClass
Bstruct
Cint
Denum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a keyword like struct instead of the class name.
3fill in blank
hard

Fix the error in the code to correctly copy a value type.

C Sharp (C#)
MyStruct copy = original[1];
Drag options to blanks, or click blank then click option'
A=>
B==
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operator == instead of assignment =.
4fill in blank
hard

Fill both blanks to create a method that accepts a value type and returns a modified copy.

C Sharp (C#)
public MyStruct Modify([1] input) { input.Number [2] 10; return input; }
Drag options to blanks, or click blank then click option'
AMyStruct
BMyClass
C+=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using a reference type as parameter instead of value type.
Using subtraction -= instead of addition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps strings to their lengths if length is greater than 3.

C Sharp (C#)
var lengths = words.Where(word => word.Length [3] 3).ToDictionary([1] => [1], [1] => [2]);
Drag options to blanks, or click blank then click option'
Aword
Bword.Length
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using length as key instead of word.
Using less than operator instead of greater than.