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

Array as reference type 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 an integer array of size 3.

C Sharp (C#)
int[] numbers = new int[[1]];
Drag options to blanks, or click blank then click option'
A1
B5
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative numbers as array size causes errors.
Forgetting to specify the size when creating the array.
2fill in blank
medium

Complete the code to assign the value 10 to the first element of the array.

C Sharp (C#)
numbers[[1]] = 10;
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the first index, which causes off-by-one errors.
Using an index outside the array bounds.
3fill in blank
hard

Fix the error in the code to copy the reference of the array correctly.

C Sharp (C#)
int[] copy = [1];
Drag options to blanks, or click blank then click option'
Anew int[3]
Bnumbers.Clone()
Cnumbers
Dnumbers.CopyTo()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Clone() creates a shallow copy, not just a reference copy.
Using CopyTo() requires parameters and does not return an array.
4fill in blank
hard

Fill both blanks to show that changing the copy affects the original array.

C Sharp (C#)
copy[[1]] = 20;
Console.WriteLine(numbers[[2]]);
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indexes for copy and numbers, which shows unrelated elements.
Using an index outside the array bounds.
5fill in blank
hard

Fill all three blanks to create a new array copy and change it without affecting the original.

C Sharp (C#)
int[] newCopy = new int[numbers.Length];
Array.[1](numbers, newCopy, numbers.[2]);
newCopy[[3]] = 30;
Console.WriteLine(numbers[1]);
Drag options to blanks, or click blank then click option'
ACopy
BLength
C1
DClone
Attempts:
3 left
💡 Hint
Common Mistakes
Using Clone creates a shallow copy but returns an object, not an array.
Changing the original array instead of the copy.