properties - Property vs Function (specifically .NET) -


I have read some discussions about this subject, and there is something I do not understand.

The most common answer looks like: Use readline properties to return cached data, use the function to return non-cached data. Do not use only write property, because "it does not understand".

There is no performance reason for this. In IL, MyProperty exists as the get_MyProperty and set_MyProperty methods. The only reason obviously is that the above answer should be assumed.

OK, then why bother at ReyDonline properties? Why not make the variable public rather than just private? Then why bother with properties ? Cached Data -> Public Variables, Non-Cache Data -> Function, Writing Data -> Sub

Let's forget all of the above, and use the properties as a useful feature? To use a 'item' common sense to get and set up data, to know what will get cached data will not return (potentially delayed).

-Edit- I think people more or less that the qualities are the best option. I did not understand why I saw so many discussions, where people were advocating against property.

The reason for reading a good quality is calculated. There is no variable to export in this case.

For example

  public class person {private readonly date time_birthday; Public internet usage {return (datetime) now - _birthday. Total years; }} ...}  

Whether to expose birthdays as a property or as an area, is definitely the issue of debate. But for other calculation values ​​such as age, the only way to expose them as a variable is to store them in the object. In this case, there is essentially redundant information stored due to being an additional variable for age. It is a minor overhead highlighting as property to be calculated and avoids unnecessary data collection


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -