C Sharp Arrays Questions and Answers
Practice ModeShowing 10 of 30 questions
Q21
Which loop is commonly used to iterate through all elements of an array?
Answer: Option A
Explanation: foreach loop is specifically designed for iterating through collections like arrays.
Q22
How do you initialize an array with values at declaration?
Answer: Option A
Explanation: Use curly braces {} to provide initial values when declaring an array.
Q23
What is the difference between Array.Copy() and Array.Clone()?
Answer: Option A
Explanation: Clone() creates a shallow copy while Copy() requires existing destination array.
Q24
Which property gives the rank (number of dimensions) of an array?
Answer: Option A
Explanation: The Rank property returns the number of dimensions of an array.
Q25
How do you resize an array in C#?
Answer: Option A
Explanation: Array.Resize() method changes the size of an array, creating a new array if needed.
Q26
What is the output of Array.BinarySearch() if element is not found?
Answer: Option A
Explanation: BinarySearch returns a negative number when element is not found.
Q27
Which collection is similar to array but can dynamically grow?
Answer: Option A
Explanation: List<T> can dynamically resize unlike arrays which have fixed size.
Q28
How do you clear all elements of an array?
Answer: Option A
Explanation: Array.Clear() method sets all elements to their default values.
Q29
What is the main advantage of using arrays over lists?
Answer: Option A
Explanation: Arrays have better performance for fixed-size collections due to direct memory access.
Q30
Which method converts an array to string representation?
Answer: Option A
Explanation: String.Join() can concatenate array elements with a separator into a string.