What will be the output of the following C# code? [code] static void Main(string[] args) { string s1 = "Hello"; string s2 =

Thảo Justin

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     string s1 = "Hello";
     string s2 = "hello";
     if (s1 == s2)
     Console.WriteLine("Equal");
     else
     Console.WriteLine("Unequal");
     if (s1.Equals (s2))
     Console.WriteLine("Equal");
     else
     Console.WriteLine("Unequal");
     Console.ReadLine();
 }
A.
Equal
Unequal
B.
Unequal
Equal
C.
Equal
Equal
D.
Unequal
Unequal
 
Answer: d
Explanation: In first comparison it is being checked either two strings are equal or not but in second comparison it is checked whether two references are equal or not.
Output:
Code:
        Unequal
        Unequal
 

Tìm kiếm

Back
Top