Re: What is the point of properties?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Arne Vajhøj" <arne@xxxxxxxxxx> wrote in message news:480695cf$0$90267$14726298@xxxxxxxxxxxxxxxxxx
Ignacio Machin ( .NET/ C# MVP ) wrote:
I have a colleague who dislikes properties - and much prefers to write
"string GetName()" and "void SetName(string name)" methods for example.

Using a property is clearer, more compact notation.

They are clearer because people expect them.

Unfortunately sometimes people forget that they are really
methods.

Arne



Properties and Methods are not the same. You cannot use the databinding features of the framework on properties - you must use methods, even if they are nothing more than a simple get/set. This is because properties are "executed" by the compiler and methods are "executed" by the runtime. For a property, there is a specific offset from the object (or stack frame) base pointer to the address of the property. The compiler computes this offset and generates code that uses this information. A method, on the other hand, generates code that gets executed by the runtime. Thus, properties tend to be slightly faster but methods are more flexible.

Mike.


.



Relevant Pages

  • Re: COBOL tool
    ... has a virtual length of 9 digits but occupies 5 actual bytes), ... it is called a 'compiler'. ... How hard would it be to write a couple of lines around a record layout ... and have a popup window that would give you the offset ...
    (comp.lang.cobol)
  • Re: COBOL tool
    ... it is called a 'compiler'. ... select with the mouse all or part of a COBOL record layout viewed in your ... and have a popup window that would give you the offset ...
    (comp.lang.cobol)
  • Re: procedure parameter struct order
    ... [original poster wrote] ... so the stack should be used in any cases. ... it does depend on the compiler -- but be aware that just ... field will be at offset 0, the next at an offset no less than ...
    (comp.lang.c)
  • Re: memmove() Usage
    ... void strdel(char *s, size_t offset, size_t count) ... since the function returns type void. ... The compiler might complain, though it's probably harmless if it ... Let's use this string as an example: ...
    (comp.lang.c)
  • Re: Advice Needed...
    ... arrays but decided against it for very good reason. ... Every compiler is capable of compiling the offset as a ... constant into the base address as - guess what - a ~constant offset~. ... to be as clear as possible -- Paul Vick is the single person most responsible ...
    (microsoft.public.vb.general.discussion)