Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the object is an integer using a type pattern.
C Sharp (C#)
if (obj is [1] number) { Console.WriteLine($"Number: {number}"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong type like 'string' instead of 'int'.
Forgetting to declare the variable after the type.
✗ Incorrect
The 'is' keyword with 'int' checks if obj is an integer and assigns it to 'number'.
2fill in blank
mediumComplete the code to check if the object is a string and has length greater than 5.
C Sharp (C#)
if (obj is [1] text && text.Length > 5) { Console.WriteLine($"Long text: {text}"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'string' for text.
Not declaring the variable after the type.
✗ Incorrect
The 'is string text' pattern checks if obj is a string and assigns it to 'text'.
3fill in blank
hardFix the error in the type pattern to correctly check for a double value.
C Sharp (C#)
if (obj is [1] value) { Console.WriteLine($"Double value: {value}"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'double'.
Using 'string' or 'bool' for numeric checks.
✗ Incorrect
The correct type to check for a double value is 'double'.
4fill in blank
hardFill both blanks to create a type pattern that checks if obj is a bool and true.
C Sharp (C#)
if (obj is [1] flag && flag [2] true) { Console.WriteLine("Flag is true"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'bool' for the type.
Using '!=' instead of '==' for comparison.
✗ Incorrect
The pattern checks if obj is a bool and if the flag equals true.
5fill in blank
hardFill both blanks to create a type pattern that checks if obj is a string with length less than 4 and prints it.
C Sharp (C#)
if (obj is [1] text && text.Length [2] 4) { Console.WriteLine($"Short text: {text}"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'string' for the type.
Using '>' instead of '<' for the length comparison.
✗ Incorrect
The code checks if obj is a string and if its length is less than 4.