31
What is the correct way to access the last element in an array named numbers in C#?
A)
numbers[numbers.Length]
B)
numbers[numbers.Length + 1]
C)
numbers.Last()
D)
numbers[numbers.Length - 1]
Answer & Solution
Answer: Option
D
32
Which method is used to concatenate two or more strings in C#?
A)
Concat()
B)
Merge()
C)
Append()
D)
Join()
Answer & Solution
Answer: Option
A
33
What is the correct syntax to declare a 2D array with 3 rows and 4 columns in C#?
A)
int[][] matrix = new int[3][4];
B)
int matrix[3, 4];
C)
int[3][4] matrix;
D)
int[,] matrix = new int[3, 4];
Answer & Solution
Answer: Option
D
34
What is the result of the expression string[] fruits = {"Apple", "Banana", "Orange"}; in C#?
A)
A compilation error
B)
Initializes an empty array
C)
Declares an array with three elements
D)
Initializes an array with three elements
Answer & Solution
Answer: Option
C
35
In C#, which method is used to find the index of the first occurrence of a specified value in an array?
A)
Search()
B)
IndexOf()
C)
Locate()
D)
None of the above
Answer & Solution
Answer: Option
B
36
What is the correct way to declare and initialize a string array with three elements in C#?
A)
colors = new string[3] {"Red", "Green", "Blue"};
B)
string[] colors = {"Red", "Green", "Blue"};
C)
string[] colors = new string[] {"Red", "Green", "Blue"};
D)
string colors[] = {"Red", "Green", "Blue"};
Answer & Solution
Answer: Option
C
37
In C#, what is the correct way to access the length of a string named text?
A)
text.Length()
B)
text.Size()
C)
text.Count()
D)
text.Length
Answer & Solution
Answer: Option
D
38
What does the IndexOf() method return if the specified value is not found in an array in C#?
A)
0
B)
Null
C)
FALSE
D)
-1
Answer & Solution
Answer: Option
D
39
What is the purpose of the Reverse() method when applied to an array in C#?
A)
Sorts the elements of the array
B)
Throws an exception
C)
Reverses the order of elements in the array
D)
Returns a copy of the array in reverse order
Answer & Solution
Answer: Option
C
40
In C#, what method is used to convert a string to an array of characters?
A)
Split()
B)
ConvertToArray()
C)
ToArray()
D)
ToCharArray()
Answer & Solution
Answer: Option
D