Internal Representation of Properties
Many programmers (especially those who program with a C-based language such as C++) tend to
name traditional accessor and mutator methods using get_ and set_ prefixes (e.g., get_Name() and
set_Name()). This naming convention itself is not problematic as far as C# is concerned. However, it
is important to understand that under the hood, a property is represented in CIL code using these
same prefixes.
For example, if you open up the EmployeeApp.exe assembly using ildasm.exe, you see that each
property is mapped to hidden get_XXX()/set_XXX() methods called internally by the CLR (see
Figure 5-10).
Figure 5-10.
A property is represented by get/set methods internally.
Assume the Employee type now has a private member variable named empSSN to represent
an individual’s Social Security number, which is manipulated by a property named
SocialSecurityNumber (and also assume you have updated your type’s custom constructor
and DisplayStats() method to account for this new piece of field data).
Do'stlaringiz bilan baham: |