What will be the output of the following C# code? | Question 16

63. What will be the output of the following C# code?

using System;

namespace MyApplication {
  class Program {
    static void Main(string[] args) {
      string[] mobiles = {"iPhone", "Samsung", "Vivo"};
      Console.WriteLine(mobiles[-1]);
    }
  }
}
  1. None
  2. Warning
  3. Exception
  4. System.String[]

Answer: C) Exception

Explanation:

The array index starts from 0 in C#, in the above code – we are trying to get the element with index -1. Thus, there will be an exception "System.IndexOutOfRangeException: Index was outside the bounds of the array."

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.