Bird
0
0

Identify the error in this C# code snippet:

medium📝 Debug Q14 of 15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this C# code snippet:
string message = 'Welcome';
Console.WriteLine(message);
AConsole.WriteLine cannot print strings
BMissing semicolon after string declaration
CUsing single quotes for string instead of double quotes
DVariable name 'message' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check string literal syntax

    In C#, strings must be enclosed in double quotes, not single quotes.
  2. Step 2: Verify other parts

    Semicolon is present, Console.WriteLine can print strings, and variable name is valid.
  3. Final Answer:

    Using single quotes for string instead of double quotes -> Option C
  4. Quick Check:

    Strings need double quotes [OK]
Quick Trick: Strings use double quotes, chars use single quotes [OK]
Common Mistakes:
MISTAKES
  • Using single quotes for strings
  • Assuming missing semicolon error
  • Thinking Console.WriteLine can't print strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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