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

Constant patterns in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the variable value equals 10 using a constant pattern.

C Sharp (C#)
if (value is [1]) {
    Console.WriteLine("Value is 10");
}
Drag options to blanks, or click blank then click option'
A"10"
B10
Cvalue
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Using the variable name instead of a constant.
Using a boolean value instead of a constant.
2fill in blank
medium

Complete the code to print a message when input equals the character 'A' using a constant pattern.

C Sharp (C#)
if (input is [1]) {
    Console.WriteLine("Input is A");
}
Drag options to blanks, or click blank then click option'
A'A'
B"A"
CA
D'a'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes which makes it a string.
Using uppercase without quotes.
Using lowercase character instead of uppercase.
3fill in blank
hard

Fix the error in the code to correctly check if status equals the boolean constant true using a constant pattern.

C Sharp (C#)
if (status is [1]) {
    Console.WriteLine("Status is true");
}
Drag options to blanks, or click blank then click option'
A"true"
BTrue
Ctrue
DTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase True or TRUE which are invalid.
Using quotes which makes it a string.
Using incorrect casing.
4fill in blank
hard

Fill both blanks to check if number is either 0 or 1 using constant patterns in a switch expression.

C Sharp (C#)
string result = number switch {
    [1] => "Zero",
    [2] => "One",
    _ => "Other"
};
Drag options to blanks, or click blank then click option'
A0
B1
C"0"
D"1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string constants instead of numeric constants.
Mixing quotes and no quotes incorrectly.
Using wrong numbers.
5fill in blank
hard

Fill all three blanks to create a switch expression that returns a message for grade being 'A', 'B', or any other character using constant patterns.

C Sharp (C#)
string message = grade switch {
    [1] => "Excellent",
    [2] => "Good",
    [3] => "Needs Improvement"
};
Drag options to blanks, or click blank then click option'
A'A'
B'B'
C_
D'C'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes for characters.
Not using the discard pattern for the default case.
Using wrong characters.