Bird
0
0

Identify the error in this C# method that tries to reset a private integer field 'score' to zero:

medium📝 Debug Q6 of 15
C Sharp (C#) - Classes and Objects
Identify the error in this C# method that tries to reset a private integer field 'score' to zero:
public void ResetScore() {
  score == 0;
}
AMethod name should be lowercase.
BMissing return type in method declaration.
CUsing '==' instead of '=' for assignment.
DMissing semicolon after method declaration.
Step-by-Step Solution
Solution:
  1. Step 1: Check the assignment statement

    The statement uses '==' which is a comparison operator, not assignment.
  2. Step 2: Correct the syntax

    Assignment requires a single '=', so it should be 'score = 0;'.
  3. Final Answer:

    Using '==' instead of '=' for assignment. -> Option C
  4. Quick Check:

    Assignment needs '=' not '==' [OK]
Quick Trick: Use '=' for assignment, '==' for comparison [OK]
Common Mistakes:
MISTAKES
  • Confusing assignment '=' with equality '=='
  • Ignoring missing semicolon after statement
  • Thinking method names must be lowercase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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