Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Property vs. Method
Message
De
16/10/2008 11:47:48
 
 
À
16/10/2008 11:44:20
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01354904
Message ID:
01355402
Vues:
22
>>The age old questions. Should I use a property or a method? Is one faster than the other?
>
>Einar,
>I just looked this up in book Framework Design Guidelines (ISBN-10:0-321-24675-6). This is focused more on resuable frameworks instead of general code, but I think a lot of the ideas still apply:
>
>Use a property, rather than a method, if the value of the property is stored in the process memory and the property would just provide access to the value. (I think we can all agree on this)
>
>Use a method, rather than a property, in the following situations:
>-The operation is orders of magnitude slower than a field access would be.
>-The operation is a conversion, such as Object.ToString method. (Note that DateTime.Now property does not adhere to this guideline, and should)
>-The operation returns a different result each time it is called, even if the parameters don't change (like Guid.NewGuid).
>-The operation has a significant and observable side effect.
>-The operation returns a copy of an internal state.
>-The operation returns an array.

That is very close to what I found on the link I provided. I guess I better get that book :o)
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform