Complete the code to remove the first element from the array by shifting elements.
for (int i = 0; i < arr.Length - 1; i++) { arr[i] = arr[[1]]; }
We shift each element to the left by assigning arr[i] = arr[i + 1].
Complete the code to set the last element to zero after shifting.
arr[arr.Length [1] 1] = 0;
We use arr.Length - 1 to access the last element and set it to zero.
Fix the error in the loop condition to avoid index out of range.
for (int i = 0; i < [1]; i++) { arr[i] = arr[i + 1]; }
The loop must stop at arr.Length - 1 to avoid accessing beyond the array.
Fill both blanks to complete the method that deletes the first element from the array.
public static void DeleteFirst(int[] arr) {
for (int i = 0; i < [1]; i++) {
arr[i] = arr[i [2] 1];
}
arr[arr.Length - 1] = 0;
}The loop runs till arr.Length - 1 and shifts elements left by using i + 1.
Fill all three blanks to create a method that deletes the first element and returns the new array length.
public static int DeleteFirstElement(int[] arr) {
for (int i = 0; i < [1]; i++) {
arr[i] = arr[i [2] 1];
}
arr[arr.Length [3] 1] = 0;
return arr.Length - 1;
}The loop runs till arr.Length - 1, shifts elements using i + 1, and sets last element at arr.Length - 1 to zero.
