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 text = "Hello World";
string part = text.Substring(6);
Console.WriteLine(part);
AWorldHello
BHello
CWorld
DHello World
Step-by-Step Solution
Solution:
  1. Step 1: Understand Substring with one parameter

    Substring(6) extracts from index 6 to end of string.
  2. Step 2: Identify substring starting at index 6

    Index 6 is the 'W' in "World", so substring is "World".
  3. Final Answer:

    World -> Option C
  4. Quick Check:

    Substring(start) extracts till end [OK]
Quick Trick: Substring with one argument extracts from start index to end [OK]
Common Mistakes:
MISTAKES
  • Assuming substring length is fixed
  • Confusing index 6 with 5
  • Expecting substring to include 'Hello'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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