Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to match a point with coordinates (0, 0).
C Sharp (C#)
if (point is ([1], 0)) { Console.WriteLine("Point is on the Y axis."); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of a literal 0.
Using 1 instead of 0.
✗ Incorrect
The pattern (0, 0) matches a point at the origin. Here, the first coordinate must be 0.
2fill in blank
mediumComplete the code to extract the X coordinate from a point using positional patterns.
C Sharp (C#)
if (point is ([1], int y)) { Console.WriteLine($"X coordinate is {x}"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'x' without type.
Using 'var x' which is invalid in positional patterns.
✗ Incorrect
To extract the X coordinate, declare it as int x in the pattern.
3fill in blank
hardFix the error in the positional pattern to correctly match a point with X > 0.
C Sharp (C#)
if (point is (int x, int y) && x [1] 0) { Console.WriteLine("X is positive."); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which checks for negative values.
Using '==' which checks for equality.
✗ Incorrect
The condition x > 0 checks if X is positive.
4fill in blank
hardFill both blanks to match a point where X equals Y.
C Sharp (C#)
if (point is ([1] x, [2] y) && x == y) { Console.WriteLine("X equals Y."); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing types like int and double.
Using 'var' which is not allowed in positional patterns.
✗ Incorrect
Both X and Y should be declared as int to match integer coordinates.
5fill in blank
hardFill all three blanks to create a method that uses positional patterns to check if a point is at the origin.
C Sharp (C#)
bool IsOrigin((int x, int y) point) => point is ([1], [2]); // Usage var p = (0, 0); Console.WriteLine(IsOrigin(p)); // [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-zero values in the pattern.
Returning false instead of true for the origin.
✗ Incorrect
The pattern (0, 0) matches the origin. The method returns true for point (0,0).