Posts

C# Questions Part 2

Image
  32.  What is an array? Explain Single and multi-dimensional arrays. The array stores the value of the same type. Single-dimensional array stores variables in a single row.  int[] marks = new int[3] { 25, 34, 89 }; Arrays can have more than one dimension. Multi-dimensional arrays are also called rectangular Arrays . int[,] numbers = new int[3, 2] { { 1, 2 }, { 2, 3 }, { 3, 4 } }; 33.   What is the difference between the System.Array.CopyTo() and System.Array.Clone() ? CopyTo():   All the items are copied to the existing array Required a pre-allocated destination array Overwrites the elements in the destination array starting from the specified index.  It allows you to control where the copying starts in the destination array. Clone():   Creates and returns a new array with the same elements as the original array Don't need to pre-allocate the destination array It doesn't overwrite any existing elements. Both ways create a  shallow copy . 1 int [ ...