Home / CSE MCQs / C#.Net MCQs :: C# Arrays and Strings

CSE MCQs :: C#.Net MCQs

  1. What is the advantage of using 2D jagged array over 2D rectangular array?
  2. A.
    Easy initialization of elements
    B.
    Allows unlimited elements as well as rows which had '0' or are empty in nature
    C.
    All of the mentioned
    D.
    None of the mentioned

  3. Which statement is correct about following set of code ? 

    int[, ]a={{5, 4, 3},{9, 2, 6}};
  4. A.
    'a' represents 1-D array of 5 integers
    B.
    a.GetUpperBound(0) gives 9
    C.
    'a' represents rectangular array of 2 columns and 3 arrays
    D.
    a.GetUpperBound(0) gives 2

  5. Choose Output for the following set of code :

    static void Main(string[] args)
    {
        string s1 = "Hello" + " I " + "Love" + " ComputerScience ";
        Console.WriteLine(s1);
        Console.ReadLine();
    }
  6. A.
    HelloILoveComputerScience
    B.
    Hello I Love ComputerScience
    C.
    Compile time error
    D.
    Hello

  7. Which of these data type values is returned by equals() method of String class?
  8. A.
    char
    B.
    int
    C.
    boolean
    D.
    All of the mentioned

  9. What will be the output for the given code snippet?

    static void Main(string[] args)
      {
          string s = " i love you";
          Console.WriteLine(s.IndexOf('l') + "  " + s.lastIndexOf('o') + "  " + s.IndexOf('e'));
          Console.ReadLine();
      }
  10. A.
    3 5 7
    B.
    4 5 6
    C.
    3 9 6
    D.
    2 4 6

  11. What will be the output of the following set of code?

    class sum   
     {
         public int x;
         public int y;
         public  int add (int a,  int b)
         {
             x = a + b;
             y = x + b;
             return 0;
         }
     }    
     class Program
     {
         static void Main(string[] args)
         {
             sum obj1 = new sum();
             sum obj2 = new sum();   
             int a = 2;
             obj1.add(a,  a + 1);
             obj2.add(5,  a);
             Console.WriteLine(obj1.x + "  " + obj2.y);     
             Console.ReadLine();
         }
     }
  12. A.
    6, 9
    B.
    5, 9
    C.
    9, 10
    D.
    3, 2

  13. What will be the output for the given set of code?

    static void Main(string[] args)
     {
         String c = "Hello";
         String a = c + "Bye";
         Console.WriteLine(a);
         Console.ReadLine();
     }
  14. A.
    Hello Bye"
    B.
    HelloBye"
    C.
    Hello Bye
    D.
    HelloBye

  15. What would be the output for the following set of code?

    static void Main(string[] args)
     {
         String obj = "hello";
         String obj1 = "world";   
         String obj2 = obj;
         Console.WriteLine (obj.Equals(obj2) + "  " + obj2.CompareTo(obj) );
         Console.ReadLine();
     }
  16. A.
    True True
    B.
    False False
    C.
    True 0
    D.
    False 1

  17. What will be the output of given set of code?

    static void main(string[] args)
     {
         int i;
         int res = fun (out i);
         console.writeline(res);
         console.readline();
     }
     static int fun(out int i)
     {
         int s = 1;
         i = 7;
         for (int j = 1; j <= i; j++ )
         s = s * j;
         return s;
     }
  18. A.
    4490
    B.
    5040
    C.
    5400
    D.
    3500

  19. What will be the output the of given set of code?

    static void Main(string[] args)
     {
         int [] a = {1, 2, 3, 4, 5};
         fun(a);
         Console.ReadLine();
     }
     static void fun(params int[] b )
     {
         for (int i = 0; i < b.Length; i++)
         {
             b[i] = b[i] * 5 ;
             Console.WriteLine(b[i] + "");
         }
     }
  20. A.
    1, 2, 3, 4, 5
    B.
    5, 10, 15, 20, 25
    C.
    5, 25, 125, 625, 3125
    D.
    6, 12, 18, 24, 30