Bird
Raised Fist0

Which of the following is the correct syntax for an auto-implemented property with get and set accessors in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Properties and Encapsulation
Which of the following is the correct syntax for an auto-implemented property with get and set accessors in C#?
Apublic int Age { get() set(); }
Bpublic int Age() { get; set; }
Cpublic int Age { get; set; }
Dpublic int Age get; set;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct property syntax

    Auto-properties use curly braces with get and set accessors separated by semicolons.
  2. Step 2: Check each option

    public int Age { get; set; } matches the correct syntax: public int Age { get; set; }
  3. Final Answer:

    public int Age { get; set; } -> Option C
  4. Quick Check:

    Auto-property syntax = C [OK]
Quick Trick: Auto-properties use braces with get; set; inside [OK]
Common Mistakes:
MISTAKES
  • Using parentheses instead of braces
  • Missing semicolons after get and set
  • Writing get and set without braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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