1
What is the correct way to declare a string array in C#?
A)
string[] colors;
B)
array colors;
C)
string colors[];
D)
colors[] = string;
Answer & Solution
Answer: Option
A
2
How do you access the first element of an array named 'numbers' in C#?
A)
first(numbers);
B)
numbers.first;
C)
numbers(1);
D)
numbers[0];
Answer & Solution
Answer: Option
D
3
What is the correct way to initialize an array of integers with values {1, 2, 3} in C#?
A)
int[] numbers = new int[] {1, 2, 3};
B)
int numbers[] = {1, 2, 3};
C)
int[] numbers = {1, 2, 3};
D)
numbers[] = {1, 2, 3};
Answer & Solution
Answer: Option
C
4
Which of the following statements is true regarding arrays in C#?
A)
Arrays in C# can dynamically resize
B)
The length of an array cannot be changed
C)
Arrays in C# can only store primitive types
D)
None of the above
Answer & Solution
Answer: Option
B
5
How do you find the number of elements in an array named 'values' in C#?
A)
Length(values);
B)
values.Count;
C)
values.Length;
D)
values.Size;
Answer & Solution
Answer: Option
C
6
What is the correct syntax to declare and initialize a 2D array in C# with dimensions 3x3?
A)
int[3,3] matrix;
B)
int[3][3] matrix;
C)
int matrix[][] = new int[3][3];
D)
int[,] matrix = new int[3,3];
Answer & Solution
Answer: Option
D
7
Which method in C# is used to sort the elements of an array in ascending order?
A)
Array.Sort()
B)
Array.Reverse()
C)
Array.Find()
D)
Array.IndexOf()
Answer & Solution
Answer: Option
A
8
What does the 'Length' property of an array in C# return?
A)
The number of characters in the array
B)
The number of dimensions in the array
C)
The size of the array in bytes
D)
The total number of elements in the array
Answer & Solution
Answer: Option
D
9
What is the correct way to declare an array of strings with 5 elements in C#?
A)
string[5] names;
B)
string[5] names = new string[];
C)
string[] names = new string[5];
D)
names[] = new string[5];
Answer & Solution
Answer: Option
C
10
How do you access the last element of an array named 'values' in C#?
A)
values[length(values)];
B)
values[values.Length - 1];
C)
Last(values);
D)
None of the above
Answer & Solution
Answer: Option
B