Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Property vs. Method
Message
 
 
À
15/10/2008 14:20:28
Mike Yearwood
Toronto, Ontario, Canada
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:
01355209
Vues:
24
>>>>The age old questions. Should I use a property or a method? Is one faster than the other?
>>>
>>>From Tracy's link:
>>>
>>>In general, methods represent actions and properties represent data.
>>>
>>>Rarely stray from the generalization. That way, in general a property will be faster than a method as there is no cumbersome execution likely to occur.
>>
>>What do methods act on? Nothing?
>
>Well, obviously parameters. Surely you know a method need not read/write any properties at all. However, imagine a property with a huge set of code fired from a get method and other properties also firing their own set(s) of code. All you're trying to do is get the value and it takes a few seconds? I'd rather rely on accessing a property taking minimal execution time and minimal debugging time too.

Surely I do know a method not read or write any properties at all. I'm not sure you're answering the question that was asked. You're comparing a "huge set of code" to a simple get accessor. My understanding of the original question was which is faster, OTHER THINGS BEING EQUAL? i.e. equal amounts of code.

Personally I also prefer the cleanness of a property. Whether it's actually faster than an equally simple method, I don't know.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform