Bird
0
0

What does the Contains method do when used on a string in C#?

easy🧠 Conceptual Q1 of 15
C Sharp (C#) - Strings and StringBuilder
What does the Contains method do when used on a string in C#?
AReplaces a substring with another string
BReturns the position of a substring
CExtracts a substring from the string
DChecks if a substring exists within the string
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of Contains method

    The Contains method checks if a specified substring is present anywhere inside the string and returns a boolean value.
  2. Step 2: Compare with other string methods

    Unlike IndexOf which returns position, Contains only returns true or false if substring exists.
  3. Final Answer:

    Checks if a substring exists within the string -> Option D
  4. Quick Check:

    Contains method = boolean check [OK]
Quick Trick: Contains returns true/false if substring is found [OK]
Common Mistakes:
MISTAKES
  • Confusing Contains with IndexOf
  • Thinking Contains returns substring position
  • Assuming Contains extracts substring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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