Bird
0
0

Which statement about the C# string method IndexOf is TRUE?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Strings and StringBuilder
Which statement about the C# string method IndexOf is TRUE?
AIt returns the last index of a substring in the string
BIt only works with single characters, not strings
CIt throws an exception if substring is missing
DIt returns -1 if the substring is not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand IndexOf behavior

    IndexOf returns the first index of the substring or -1 if not found.
  2. Step 2: Evaluate options

    It does not throw exceptions and works with strings and chars.
  3. Final Answer:

    It returns -1 if the substring is not found -> Option D
  4. Quick Check:

    IndexOf returns -1 when missing [OK]
Quick Trick: IndexOf returns -1 if substring missing [OK]
Common Mistakes:
MISTAKES
  • Thinking it throws exceptions
  • Confusing with LastIndexOf
  • Believing it only works with chars

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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