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));
  }
}
  1. Error
  2. True True
  3. True False
  4. 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.

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.