What will be the output of the following C# code snippet? [code] static void Main(string[] args) { String a ="i love iostream";

Mỹ An

New member
What will be the output of the following C# code snippet?
Code:
 static void Main(string[] args)
 {
     String a ="i love iostream";
     Console.WriteLine(a.IndexOf('i') + " " + a.IndexOf('e') + " " + a.LastIndexOf('i') + " " + a.LastIndexOf('e'));
     Console.ReadLine();
 }
A. 0 6 7 8
B. 0 5 7 9
C. 5 9 0 7
D.
Code:
0 5 7 12
 
Answer: d
Explanation: indexof(‘i’) and lastIndexof(‘i’) are pre defined functions which are used to get the index of first and last occurrence of the character pointed by i in the given array.
Output :
Code:
0 5 7 12
 

Tìm kiếm

Back
Top