Bird
Raised Fist0

Identify the error in this code snippet:

medium📝 Debug Q14 of Q15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this code snippet:
string s = "Example";
if(s.Contains("ex"))
{
    Console.WriteLine("Found");
}
AContains() is case-sensitive, so "ex" won't match "Ex"
BMissing semicolon after if statement
CContains() method does not exist for strings
DConsole.WriteLine syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check Contains() behavior

    Contains() is case-sensitive, so "ex" does not match "Ex" in "Example".
  2. Step 2: Verify syntax correctness

    Semicolons and method calls are correct; no syntax errors present.
  3. Final Answer:

    Contains() is case-sensitive, so "ex" won't match "Ex" -> Option A
  4. Quick Check:

    Contains() case matters = true [OK]
Quick Trick: Remember Contains() is case-sensitive by default [OK]
Common Mistakes:
MISTAKES
  • Assuming Contains() ignores case
  • Looking for syntax errors that don't exist
  • Confusing method availability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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