Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
string s1 = “Hello I Love Csharp “;
Console.WriteLine(Convert.ToChar( (s1.IndexOf(‘I’) – s1.IndexOf(‘l’)) * s1.IndexOf(‘p’));
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
string s1 = “Hello I Love Csharp “;
Console.WriteLine(Convert.ToChar( (s1.IndexOf(‘I’) – s1.IndexOf(‘l’)) * s1.IndexOf(‘p’));
Console.ReadLine();
}
a) I
b) Hello I
c) Love
d) H

Answer: d
Explanation: ‘I’ = index position[6], ‘l’ = index position[2]. So, I – l = 6-2 = 4*(index position of p = 18) = 72. Character with ASCII Value 72 = ‘H’.

Join The Discussion