Bird
0
0

What is the output of the following C# code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Strings and StringBuilder
What is the output of the following C# code?
string s1 = "Hello";
string s2 = "hello";
bool result = s1.Equals(s2, StringComparison.OrdinalIgnoreCase);
Console.WriteLine(result);
AFalse
BRuntime exception
CCompilation error
DTrue
Step-by-Step Solution
Solution:
  1. Step 1: Understand Equals with OrdinalIgnoreCase

    This compares strings ignoring case, so "Hello" and "hello" are equal.
  2. Step 2: Determine output of Console.WriteLine

    Since result is true, output is True.
  3. Final Answer:

    True -> Option D
  4. Quick Check:

    Equals with OrdinalIgnoreCase returns True for case difference [OK]
Quick Trick: Equals with OrdinalIgnoreCase returns true if strings differ only by case [OK]
Common Mistakes:
MISTAKES
  • Assuming case difference makes Equals false
  • Confusing Equals with == operator
  • Expecting compilation error due to overload

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes