C#.NET — Which statement about properties is correct?

Difficulty: Easy

Correct Answer: Properties of a class are actually methods (get/set) that behave like data members.

Explanation:


Introduction / Context:
The question probes what a property truly is under the hood in C#.NET and clarifies common misconceptions about accessors and overloading.



Given Data / Assumptions:

  • We compare statements about accessors, overloading, and nature of properties.


Concept / Approach:
A property compiles to accessor methods (get and/or set). It can be read-only (get only), write-only (set only), or read-write (both). Overloading properties by parameter list is not applicable (that is what indexers are for), and you cannot have two properties with the same name differing only by type.



Step-by-Step Solution:

A is false: properties can be read-only or write-only. B is generally true (properties are not overloaded like methods), but the most broadly accurate and explanatory statement is C. C is correct: properties are syntactic sugar for accessor methods that expose field-like syntax. D is false: a property can be read-write (both accessors).


Verification / Alternative check:
Inspect IL: a property named P compiles to methods get_P and/or set_P.



Why Other Options Are Wrong:
They either overconstrain accessors or mischaracterize property behavior; C states the core truth.



Common Pitfalls:
Confusing properties with indexers (which do take parameters) or assuming accessor presence is mandatory.



Final Answer:
Properties of a class are actually methods (get/set) that behave like data members.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion