.net - Method Vs Property -


I am a newbie for .NET. I have a class named Project, many projects can be predicted in a project.Now if I want to see if there are any predictions in the projects or not, then I should use Boolean property to read (HasForecast) or I should use a method called HasForecast () to basically give a boolean value. From the framework design guidelines I came to know that methods should be used when the operation is complex, because here I am recovering the value of the forecast from DB, I should consider the method, or because it is a logical data member, The property should be used. If I can use any asset, I can call a method in my DBAir from my planet. Please,

Please, Ravi

attribute should be very light weight which works If you need access to a database then you should use one method.

See MSDN here:

Properties vs. Ways

Class library designers often have to decide between applying a class member as an asset or method Generally, methods represent the actions and represent the data to the properties. Use the following guidelines to choose between these options.

Use a property When a member is a logical data member, in the following member declarations, the name is a property because it is a logical member of the class.

Use a method when:

  • The operation is quite expensive that you want to communicate with the user that they should consider the results caching.
  • Receiving property prices using the received asset will have an analogous effect.
  • Calling the member twice in succession produces different results.
  • The execution order is important. Note that any kind of properties should be able to set and retrieve in any order.
  • The member is static, but gives value that can be changed.
  • The member returns an array. Properties The returning arrays can be very confusing, generally it is necessary to return the copy of the internal array so that the user can not change the internal state. It has been linked to the fact that the user can easily assume that it is an indexed property, which leads to the disabled code.

  • Comments

    Popular posts from this blog

    windows - Heroku throws SQLITE3 Read only exception -

    lex - Building a lexical Analyzer in Java -

    python - rename keys in a dictionary -