answersLogoWhite

0

  1. As to access a data member of an object or class (a class can have property, or static property).
  2. A property may have different accessing modifiers (new in .net 2.0) separately for the getters and setters (the mutators)
  3. .Net framework itself uses and depends on Property feature heavily.

One of the rookie mistakes or being a lazy developer is to allow the data members being directly accessed (get and set the values) as a public field:

public class Person { public string Name; }

vs

public class BetterPersonImplementation {

public string Name {

get;

set;

}

} //the new way to declare a data member via property declaration

The first benefit of moving from direct access to Property implementation is now your class can be directly apply to a window forms (direct field access cannot!!)

The hidden benefit - you are following the object principles - encapsulation

You are denying the public to directly playing with aPerson's Name. (If it were a body part.... yak)

The other benefit: if when setting the name value, let's assume that it should never be set to "Name", and there are more than 10 assignments in your code assignements aPerson.Name = ....

You would have to insert the check "if the value != "Name" at 10 different places.

Worse yet, someone else uses your class in their codes, you have to notify them as well.... (well, you won't make this kind of mistake if someone is going to use your code in the first place, right?)

By using Property feature, you have only 1 place to make the change, while the 10 assignments (the property setter) remain the same!

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Variable vs property in net?

Property allows access to a variables like a get-set method in Java.


What is net property income?

Net operating income (NOI) is a calculation used to analyze real estate investments that generate income. Net operating income equals all revenue from the property minus all reasonably necessary operating expenses.


Is one property of an electron a net charge of 0?

No an electron does not have a net charge of 0, in fact it has a net charge of -1.


What is postback concept in net?

IS postback property to handle postbackform inused.


What are the common business exposures?

property, liability, net income, & personnel


What is the use of Ispostback in dot net?

What is the use of Ispostback in dot net?"


Does present values have value adding up property?

Net present value method has value adding-up property


What is the meaning of net as in fishing net?

it is the net you use to catch the fish in


What does rent net net net mean?

"Rent net net net" (NNN) refers to a type of commercial lease where the tenant is responsible for paying not only the base rent but also all additional expenses associated with the property. This includes property taxes, insurance, and maintenance costs. In an NNN lease, the landlord has minimal responsibilities, making it a popular choice for investors seeking stable, long-term income with reduced risk.


What are the net results of a chemical change?

change in the chemical aspect or the molecular property.


When should a person use .NET?

They should use it if they are familiar with the .NET libraries. There is no specific *time* to use it.


How do you use net user command?

net user