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

Relational 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 number is greater than 10 using a relational pattern.

C Sharp (C#)
if (number is > [1]) {
    Console.WriteLine("Number is greater than 10");
}
Drag options to blanks, or click blank then click option'
A5
B10
C15
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong number to compare.
Using a less than operator instead of greater than.
2fill in blank
medium

Complete the code to check if the age is less than or equal to 18 using a relational pattern.

C Sharp (C#)
if (age is [1] 18) {
    Console.WriteLine("Minor age");
}
Drag options to blanks, or click blank then click option'
A<=
B>
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or less than without equal.
Swapping the operator direction.
3fill in blank
hard

Fix the error in the relational pattern to check if temperature is not equal to 0.

C Sharp (C#)
if (temperature is not [1]) {
    Console.WriteLine("Temperature is not zero");
}
Drag options to blanks, or click blank then click option'
A==
B<
C>
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' inside 'is not' which is incorrect.
Using less than or greater than operators.
4fill in blank
hard

Fill both blanks to check if score is between 50 and 100 inclusive using relational patterns.

C Sharp (C#)
if (score is >= [1] and <= [2]) {
    Console.WriteLine("Score is in the passing range");
}
Drag options to blanks, or click blank then click option'
A50
B40
C100
D110
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong boundary numbers.
Swapping the lower and upper bounds.
5fill in blank
hard

Fill all three blanks to create a pattern that checks if value is greater than 0, less than 10, and not equal to 5.

C Sharp (C#)
if (value is > [1] and < [2] and not [3]) {
    Console.WriteLine("Value is valid");
}
Drag options to blanks, or click blank then click option'
A0
B10
Cis
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'is' instead of 5 for not equal.
Mixing up the boundary numbers.