Home »
MCQs »
C# MCQs
What will be the output of the following C# code? | Question 12
58. What will be the output of the following C# code?
using System;
class Program {
static void Main(string[] args) {
String s1 = "Hello";
String s2 = "IncludeHelp";
String s3 = s1;
Console.WriteLine(s1.Equals(s3) + " " + s2.CompareTo(s1));
}
}
- Error
- True True
- True False
- True 1
Answer: D) True 1
Explanation:
The Equals() method returns a bool value. We assigned s1 to s3. Thus, the statement s1.Equals(s3) will returns "True". And, the CompareTo() method returns an int value (Less than 0, o, or greater than 0). The statement s2.CompareTo(s1) will returns 1 because this instance (s2) follows s1.