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?
class Program
{
static void Main(string[] args)
{
String s1 = “I love You”;
String s2 = s1;
Console.WriteLine((s1 == s2) + ” ” + s1.Equals(s2));
Console.ReadLine();
}
}

What will be the output of the following C# code?
class Program
{
static void Main(string[] args)
{
String s1 = “I love You”;
String s2 = s1;
Console.WriteLine((s1 == s2) + ” ” + s1.Equals(s2));
Console.ReadLine();
}
}
a) true true
b) false false
c) true false
d) false true

Answer: a
Explanation: The ‘==’ operator tests the equality of strings and since s1 = “I love You” and also s2 = s1. So, true is returned. Similarly, Equals() returns true.
since the content of both s1 and s2 are equal in nature.
Output :
true true

Join The Discussion