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

Value type copying behavior 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 declare a value type variable.

C Sharp (C#)
int [1] = 10;
Drag options to blanks, or click blank then click option'
Anumber
BrefNumber
CmyClass
Dobj
Attempts:
3 left
💡 Hint
Common Mistakes
Using names that imply reference types instead of value types.
2fill in blank
medium

Complete 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'
Aref a
Ba
C&a
Dnew int()
Attempts:
3 left
💡 Hint
Common Mistakes
Using reference or address operators which are invalid here.
3fill in blank
hard

Fix 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'
Ap1
B&p1
Cref p1
Dnew Point()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign struct by reference using & or ref keywords.
4fill in blank
hard

Fill 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'
Arect1
Brect2
C15
Drect1.Width
Attempts:
3 left
💡 Hint
Common Mistakes
Modifying the original struct instead of the copy.
5fill in blank
hard

Fill 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'
Ac1
B10
C7
Dc2
Attempts:
3 left
💡 Hint
Common Mistakes
Assuming changing the copy changes the original.