Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this code snippet:
string s = "example";
int pos = s.IndexOf('a');
Console.WriteLine(pos);
ANo error, code runs correctly
BMissing semicolon after string declaration
CIndexOf requires a string, not a char
DIndexOf cannot be used with single quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check IndexOf parameter type

    IndexOf can accept a char or string, so 'a' is valid.
  2. Step 2: Verify syntax correctness

    All semicolons are present and syntax is correct.
  3. Final Answer:

    No error, code runs correctly -> Option A
  4. Quick Check:

    IndexOf accepts char or string [OK]
Quick Trick: IndexOf accepts both char and string parameters [OK]
Common Mistakes:
MISTAKES
  • Thinking single quotes are invalid for IndexOf
  • Assuming missing semicolon
  • Confusing char and string types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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