Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
class instead of struct to declare a value type.✗ Incorrect
The struct keyword declares a value type in C#.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a keyword like
struct instead of the class name.✗ Incorrect
To create an instance of a class (reference type), use the class name with new.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operator
== instead of assignment =.✗ Incorrect
Use the assignment operator = to copy value types.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a reference type as parameter instead of value type.
Using subtraction
-= instead of addition.✗ Incorrect
The method takes a value type MyStruct and adds 10 to its Number field using +=.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using length as key instead of word.
Using less than operator instead of greater than.
✗ Incorrect
The dictionary maps each word to its word.Length only if the length is greater than 3.