Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Property vs. Method
Message
 
To
14/10/2008 14:45:21
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01354904
Message ID:
01354929
Views:
14
>>>>>>The age old questions. Should I use a property or a method? Is one faster than the other?
>>>>>
>>>>>?? A property is a piece of information. A method DOES something. Very different.
>>>>
>>>>Property:
>>>>
>>>>public bool IsMyBirthDay
>>>>{
>>>>  get{return DateTime.Today == new DateTime(1976, 1, 15);}
>>>>}
>>>>
>>>>
>>>>Method:
>>>>
>>>>public bool IsMyBirthDay()
>>>>{
>>>>  return DateTime.Today == new DateTime(1976, 1, 15);
>>>>}
>>>>
>>>
>>>My inclination would be to use a method for this. But you've highlighted the issue in question - there's no simple answer although, in general, I don't like putting too much logic in get/set's.
>>
>>That is also my rule of thum, not to put to much logic into get (and set), but for some reason I start second guessing myself every 2-3 months and today is one of those days when I started second guessing myself :)
>>Thanks for the reply
>
>I'm the same way, and it's hard to draw a line between when to use one or the other. I guess it's all a matter of programming standards.

But if one way performs better, i.e. faster execution, than the other I would choose the faster way 9 out of 10 times.
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform