Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this code?
string s = "  Trim me  ";
string trimmed = s.Trim();
Console.WriteLine(trimmed.Length);
A10
B8
C9
D12
Step-by-Step Solution
Solution:
  1. Step 1: Understand Trim method effect

    Trim removes spaces from start and end of the string.
  2. Step 2: Calculate length after trimming

    Original string has 10 chars including spaces; trimmed string is "Trim me" which has 7 characters.
  3. Final Answer:

    7 -> Option B
  4. Quick Check:

    Trimmed length = 7 [OK]
Quick Trick: Trim removes spaces from both ends [OK]
Common Mistakes:
MISTAKES
  • Counting spaces after trim
  • Using TrimStart or TrimEnd instead
  • Miscounting string length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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