Bird
Raised Fist0

What is the output of the following code?

medium📝 Predict Output Q4 of Q15
C Sharp (C#) - Strings and StringBuilder
What is the output of the following code?
string s = "Hello World";
string result = s.Substring(6, 5);
Console.WriteLine(result);
AWorlds
BHello
CWorld
DolleH
Step-by-Step Solution
Solution:
  1. Step 1: Understand Substring parameters

    Substring(6, 5) means start at index 6 and take 5 characters.
  2. Step 2: Extract substring from "Hello World"

    Index 6 is 'W', next 5 characters are "World".
  3. Final Answer:

    World -> Option C
  4. Quick Check:

    Substring(6,5) = "World" [OK]
Quick Trick: Substring(start, length) extracts part of string [OK]
Common Mistakes:
MISTAKES
  • Confusing start index with length
  • Off-by-one errors
  • Expecting substring to include index 11

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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