C Sharp Arrays Questions and Answers

Practice Mode
Showing 10 of 30 questions
Q21
Which loop is commonly used to iterate through all elements of an array?
  • A foreach
  • B for
  • C while
  • D do-while
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?
  • A int[] arr = {1, 2, 3};
  • B int[] arr = [1, 2, 3];
  • C int[] arr = (1, 2, 3);
  • D int[] arr = new 1, 2, 3;
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()?
  • A Clone creates new array, Copy needs destination
  • B Copy creates new array, Clone needs destination
  • C Both work exactly the same
  • D Clone is faster than Copy
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?
  • A Rank
  • B Dimensions
  • C Length
  • D Size
Answer: Option A
Explanation: The Rank property returns the number of dimensions of an array.
Q25
How do you resize an array in C#?
  • A Array.Resize()
  • B array.Resize()
  • C Resize(array)
  • D array.Size = newSize
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?
  • A Negative number
  • B 0
  • C null
  • D -1
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?
  • A List<T>
  • B ArrayList
  • C Dictionary<T>
  • D HashSet<T>
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?
  • A Array.Clear()
  • B array.Clear()
  • C Clear(array)
  • D array.RemoveAll()
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?
  • A Better performance
  • B Dynamic resizing
  • C Built-in sorting
  • D Automatic indexing
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?
  • A String.Join()
  • B array.ToString()
  • C Convert.ToString(array)
  • D array.String()
Answer: Option A
Explanation: String.Join() can concatenate array elements with a separator into a string.
Questions and Answers for Competitive Exams Various Entrance Test