Complete the code to declare a struct named Point.
public [1] Point { public int X; public int Y; }The keyword struct is used to declare a value type in C#.
Complete the code to create a new Point struct instance with X=5 and Y=10.
Point p = new Point() { X = [1], Y = 10 };We assign X the value 5 as required.
Fix the error in the code to correctly assign one Point to another.
Point p1 = new Point() { X = 1, Y = 2 };
Point p2;
p2 = [1];Assigning p1 to p2 copies the struct values.
Fill both blanks to complete the method that returns the distance from origin.
public double Distance() {
return Math.[1](X * X + Y * Y);
}
// Usage:
Point p = new Point() { X = 3, Y = 4 };
double dist = p.[2]();The method Math.Sqrt calculates the square root. The struct method is called Distance, and usage calls the method name, which is the same here.
Fill all three blanks to complete the struct with a constructor and a method that moves the point.
public struct Point {
public int X;
public int Y;
public Point(int x, int y) {
[1] = x;
[2] = y;
}
public void Move(int dx, int dy) {
X += [3];
Y += dy;
}
}The constructor assigns parameters to fields X and Y. The Move method adds dx to X and dy to Y.
