Re: What is the point of properties?
- From: "Michael D. Ober" <obermd.@.alum.mit.edu.nospam.>
- Date: Wed, 16 Apr 2008 22:35:45 -0600
"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.
.
- Follow-Ups:
- Re: What is the point of properties?
- From: Jon Skeet [C# MVP]
- Re: What is the point of properties?
- References:
- What is the point of properties?
- From: Peter
- Re: What is the point of properties?
- From: Ignacio Machin ( .NET/ C# MVP )
- Re: What is the point of properties?
- From: Arne Vajhøj
- What is the point of properties?
- Prev by Date: Re: Down casting objects
- Next by Date: Re: What is the point of properties?
- Previous by thread: Re: What is the point of properties?
- Next by thread: Re: What is the point of properties?
- Index(es):
Relevant Pages
|