Sep 20, 2011

C# sharp objective questions and answers

Which of the following true about array declaration in c#?
(I) int [][] x = new int[2][5];
(II) int [][] x = new int[2][];
(III) int [,] x = new int[2,5];

(a) Only (I) is incorrect.
(b) Only (II) is incorrect.
(c) Only (III) is incorrect.
(d) All are correct
(e) Both (II) and (III) are in correct.

Answer: (a)
Explanation: In (I) and (II) array x is jagged array. In case of jagged array declaration we can specify size of only first dimension.

In C# Rank property is used to find the dimension of an array. What would be the output of following C# code?
using System;

namespace JaggedArrayDemo
    class Program
        static void Main(string[] args)
            //Declaration and initialization of jagged array
            int[][] arr = new int[3][];


(e)Compilation error
Answer :( b)
Explanation: arr is not two dimensional arrays it is one dimensional jagged array.

No comments: