Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Strings and StringBuilder
What is the output of this code?
string s = "hello world";
int pos = s.IndexOf("world");
string part = s.Substring(pos, 5);
Console.WriteLine(part);
Ahello
Bworldd
Cworld
Derror
Step-by-Step Solution
Solution:
  1. Step 1: Find index of "world" in string

    "world" starts at index 6 in "hello world".
  2. Step 2: Extract substring from index 6 with length 5

    Substring(6, 5) extracts "world" exactly.
  3. Final Answer:

    world -> Option C
  4. Quick Check:

    IndexOf + Substring extracts "world" [OK]
Quick Trick: IndexOf finds start, Substring extracts exact length [OK]
Common Mistakes:
MISTAKES
  • Using wrong start index for Substring
  • Confusing length parameter
  • Expecting output to include extra characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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