1. How do you declare an array of integers in C#?
Answer:
Explanation:
In C#, arrays are declared with the type followed by square brackets, as in int[].
2. What will be the default value of elements in a newly created int array in C#?
Answer:
Explanation:
By default, all elements in a new integer array in C# are initialized to zero.
3. How can you determine the length of an array in C#?
Answer:
Explanation:
The Length property is used to find the number of elements in an array in C#.
4. Which of these is a correct way to initialize an array in C#?
Answer:
Explanation:
This syntax initializes an array with specific values without specifying the size.
5. How do you access the third element in an array named 'data' in C#?
Answer:
Explanation:
Array indices in C# start at 0, so the third element is accessed with data[2].
6. What is the output of the following C# code?
int[] nums = {1, 2, 3};
Console.WriteLine(nums[1]);
Answer:
Explanation:
The index 1 corresponds to the second element in the array, which is 2.
7. How do you create a two-dimensional array in C#?
Answer:
Explanation:
A two-dimensional array is declared with two sets of square brackets and initialized with the 'new' keyword followed by the array dimensions.
8. What does the following code do in C#?
Array.Sort(myArray);
Answer:
Explanation:
Array.Sort() sorts the elements of an array in ascending order.
9. Which method is used to reverse the elements of an array in C#?
Answer:
Explanation:
Array.Reverse() is used to reverse the order of the elements in an array.
10. In C#, what exception is thrown if you access an array index that is out of bounds?
Answer:
Explanation:
Accessing an invalid array index in C# results in an IndexOutOfRangeException.
11. What is the correct way to declare a jagged array in C#?
Answer:
Explanation:
A jagged array is an array of arrays, and it is declared with two sets of square brackets.
12. How do you copy an array in C#?
Answer:
Explanation:
Array.Copy() is a static method used to copy elements from one array to another.
13. Which keyword is used to iterate over an array in C#?
Answer:
Explanation:
The foreach loop is commonly used for iterating over the elements of an array in C#.
14. What is the default value for elements in a boolean array in C#?
Answer:
Explanation:
By default, all elements in a new boolean array in C# are initialized to false.
15. How do you initialize an array of strings with 3 elements in C#?
Answer:
Explanation:
All the options are valid ways to initialize an array of strings with three elements in C#.
16. How do you check if an array is empty in C#?
Answer:
Explanation:
The Length property of the array is used to check if it is empty by comparing it to 0.
17. Which method is used to find a specific element in an array in C#?
Answer:
Explanation:
Array.Find() is used to search for an element that matches a certain condition in an array.
18. What is the result of using the Clone() method on an array in C#?
Answer:
Explanation:
The Clone() method creates a shallow copy of the array, meaning it copies the elements but not the objects they reference.
19. How do you declare an array with initial size but without initializing the elements in C#?
Answer:
Explanation:
This syntax declares an array with a specified size (5 in this case) without initializing the elements.
20. Which of the following is not a valid array declaration in C#?
Answer:
Explanation:
The correct syntax for array declaration in C# does not include the type after the array brackets.