Bird
0
0

Which of the following is the correct syntax to extract a substring starting at index 2 with length 4 from string str?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Strings and StringBuilder
Which of the following is the correct syntax to extract a substring starting at index 2 with length 4 from string str?
Astr.SubString(2, 4);
Bstr.SubStr(2, 4);
Cstr.Substring(4, 2);
Dstr.Substring(2, 4);
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct method name and parameters

    The method is Substring with capital S, taking start index and length as parameters.
  2. Step 2: Check parameter order and spelling

    Start index is 2, length is 4, so Substring(2, 4) is correct. Other options have wrong casing or parameter order.
  3. Final Answer:

    str.Substring(2, 4); -> Option D
  4. Quick Check:

    Substring syntax = Substring(start, length) [OK]
Quick Trick: Substring method uses start index then length [OK]
Common Mistakes:
MISTAKES
  • Using wrong method name casing
  • Swapping start index and length
  • Using non-existent methods like SubStr

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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