Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this C# code?
string s = "Hello";
s = s.Replace('l', 'x');
Console.WriteLine(s);
AHexxo
BHello
CHexllo
DHeXXo
Step-by-Step Solution
Solution:
  1. Step 1: Understand Replace method

    Replace('l', 'x') changes all 'l' characters to 'x'.
  2. Step 2: Apply replacement to "Hello"

    "Hello" has two 'l's, both become 'x', resulting in "Hexxo".
  3. Final Answer:

    Hexxo -> Option A
  4. Quick Check:

    Replace changes all matching chars [OK]
Quick Trick: Replace changes every matching character in the string [OK]
Common Mistakes:
MISTAKES
  • Thinking only first 'l' changes
  • Assuming original string stays unchanged
  • Confusing case sensitivity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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