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

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

using System;

class Program {
  static void Main(string[] args) {
    String str = "Hello";
    Console.WriteLine(str.IndexOf('h'));
  }
}
  1. 0
  2. 1
  3. -1
  4. Error

Answer: C) -1

Explanation:

The IndexOf() method returns the index of a given characters, and it returns -1 if the given character is not found in the string. Here, we are trying to get the index of 'h' which is not present in the string. Thus, the output will be -1.

Comments and Discussions!

Load comments ↻






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