Home »
MCQs »
C# MCQs
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'));
}
}
- 0
- 1
- -1
- 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.