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

Comparison operators 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 variable a is greater than b.

C Sharp (C#)
bool result = a [1] b;
Drag options to blanks, or click blank then click option'
A>
B<
C<=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of > to compare values.
Using < which means less than.
2fill in blank
medium

Complete the code to check if score is less than or equal to 100.

C Sharp (C#)
if (score [1] 100) {
    Console.WriteLine("Valid score");
}
Drag options to blanks, or click blank then click option'
A<=
B<
C>=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < which excludes equality.
Using >= which means greater than or equal.
3fill in blank
hard

Fix the error in the comparison to check if age is not equal to 18.

C Sharp (C#)
if (age [1] 18) {
    Console.WriteLine("Age is not 18");
}
Drag options to blanks, or click blank then click option'
A==
B!=
C<>
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using = which is assignment, not comparison.
Using <> which is not valid in C#.
4fill in blank
hard

Fill both blanks to create a dictionary that maps numbers to their squares only if the number is greater than 3.

C Sharp (C#)
var squares = new Dictionary<int, int> {
    { [1], [2] }
};
Drag options to blanks, or click blank then click option'
A4
B16
C3
D9
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as key which is not greater than 3.
Using a value that is not the square of the key.
5fill in blank
hard

Fill all three blanks to create a LINQ query that selects numbers from 1 to 5 where the number is less than 4 and doubles them.

C Sharp (C#)
var result = from num in Enumerable.Range(1, 5)
             where num [1] 4
             select num [2] [3];
Drag options to blanks, or click blank then click option'
A<
B*
C2
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than operator in the where clause.
Using addition instead of multiplication for doubling.