Complete the code to match a point with coordinates (0, 0).
if (point is ([1], 0)) { Console.WriteLine("Point is on the Y axis."); }
The pattern (0, 0) matches a point at the origin. Here, the first coordinate must be 0.
Complete the code to extract the X coordinate from a point using positional patterns.
if (point is ([1], int y)) { Console.WriteLine($"X coordinate is {x}"); }
To extract the X coordinate, declare it as int x in the pattern.
Fix the error in the positional pattern to correctly match a point with X > 0.
if (point is (int x, int y) && x [1] 0) { Console.WriteLine("X is positive."); }
The condition x > 0 checks if X is positive.
Fill both blanks to match a point where X equals Y.
if (point is ([1] x, [2] y) && x == y) { Console.WriteLine("X equals Y."); }
Both X and Y should be declared as int to match integer coordinates.
Fill all three blanks to create a method that uses positional patterns to check if a point is at the origin.
bool IsOrigin((int x, int y) point) => point is ([1], [2]); // Usage var p = (0, 0); Console.WriteLine(IsOrigin(p)); // [3]
The pattern (0, 0) matches the origin. The method returns true for point (0,0).
