21
What is the correct way to access the third element in an array named numbers in C#?
A)
numbers[3]
B)
numbers(3)
C)
numbers(2)
D)
numbers[2]
Answer & Solution
Answer: Option
D
22
What is the correct way to declare a string array named colors with three elements in C#?
A)
colors[3] = {"Red", "Green", "Blue"};
B)
string[] colors = new string[3];
C)
string[] colors = {"Red", "Green", "Blue"};
D)
colors = new string[] {"Red", "Green", "Blue"};
Answer & Solution
Answer: Option
C
23
In C#, which method is used to copy elements from one array to another?
A)
Copy()
B)
Array.Clone()
C)
Clone()
D)
Array.Copy()
Answer & Solution
Answer: Option
D
24
What is the result of the expression string[] names = {"John", "Alice", "Bob"}; in C#?
A)
A compilation error
B)
Declares an array with three elements
C)
Initializes an empty array
D)
Initializes an array with three elements
Answer & Solution
Answer: Option
B
25
What is the correct way to access the length of an array named numbers in C#?
A)
numbers.Length
B)
Length(numbers)
C)
numbers.size()
D)
Length(numbers[])
Answer & Solution
Answer: Option
A
26
What is the correct way to declare a jagged array in C#?
A)
int[][][] jaggedArray;
B)
int[,] jaggedArray;
C)
jaggedArray[]
D)
int[][] jaggedArray;
Answer & Solution
Answer: Option
D
27
In C#, which method is used to sort the elements of an array?
A)
Sort()
B)
Array.Order()
C)
Array.Sort()
D)
Order()
Answer & Solution
Answer: Option
C
28
What is the correct syntax to declare a multidimensional array in C#?
A)
int[2,2] matrix;
B)
int[,] matrix;
C)
int[2][2] matrix;
D)
None of the above
Answer & Solution
Answer: Option
B
29
What does the Split() method do when applied to a string in C#?
A)
Converts the string to lowercase
B)
Converts the string to uppercase
C)
Splits the string into an array of substrings based on a delimiter
D)
Concatenates the string with another string
Answer & Solution
Answer: Option
C
30
In C#, which method is used to convert an array to a string representation?
A)
ToString()
B)
Convert()
C)
Join()
D)
Array.ToString()
Answer & Solution
Answer: Option
C