Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a value type variable.
C Sharp (C#)
int [1] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using names that imply reference types instead of value types.
✗ Incorrect
The variable number is a simple value type variable of type int.
2fill in blank
mediumComplete the code to copy the value of one variable to another.
C Sharp (C#)
int a = 5; int b = [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reference or address operators which are invalid here.
✗ Incorrect
Assigning b = a copies the value of a into b.
3fill in blank
hardFix the error in copying a struct value.
C Sharp (C#)
struct Point { public int X; public int Y; }
Point p1 = new Point { X = 1, Y = 2 };
Point p2 = [1];
p2.X = 5; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign struct by reference using & or ref keywords.
✗ Incorrect
Assigning p2 = p1 copies the struct value. Using &p1 or ref p1 is invalid here.
4fill in blank
hardFill both blanks to create a copy of a struct and modify it without changing the original.
C Sharp (C#)
struct Rectangle { public int Width; public int Height; }
Rectangle rect1 = new Rectangle { Width = 10, Height = 20 };
Rectangle rect2 = [1];
rect2.Width = [2]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Modifying the original struct instead of the copy.
✗ Incorrect
Assigning rect2 = rect1 copies the value. Changing rect2.Width to 15 does not affect rect1.
5fill in blank
hardFill all three blanks to demonstrate that changing a copied value type does not affect the original.
C Sharp (C#)
struct Circle { public int Radius; }
Circle c1 = new Circle { Radius = 7 };
Circle c2 = [1];
c2.Radius = [2];
Console.WriteLine(c1.Radius == [3]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assuming changing the copy changes the original.
✗ Incorrect
Assigning c2 = c1 copies the value. Changing c2.Radius to 10 does not change c1.Radius, which remains 7.