Bird
0
0

Find the error in this C# method that tries to increment a private field 'counter':

medium📝 Debug Q7 of 15
C Sharp (C#) - Classes and Objects
Find the error in this C# method that tries to increment a private field 'counter':
public void IncreaseCounter() {
  counter = counter + 1
}
AIncorrect method return type.
BMissing semicolon at the end of the statement.
CMethod name should be 'increaseCounter'.
DCannot modify private fields inside methods.
Step-by-Step Solution
Solution:
  1. Step 1: Check the statement syntax

    The statement 'counter = counter + 1' is missing a semicolon at the end.
  2. Step 2: Confirm method syntax rules

    Statements in C# must end with a semicolon to compile correctly.
  3. Final Answer:

    Missing semicolon at the end of the statement. -> Option B
  4. Quick Check:

    Statements require semicolons [OK]
Quick Trick: Always end statements with semicolons [OK]
Common Mistakes:
MISTAKES
  • Forgetting semicolons after statements
  • Thinking method names must be camelCase
  • Believing private fields can't be changed inside class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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