J
Janaka
I'm having a discussion with my colleagues here on good programming
standards. One thing we haven't agreed on is the use of properties in
classes vs using member variables. Now everyone knows that it is useful to
use a property when it has to do some further action on the data such as
private double salesAvg;
public double SalesAverage
{
set {
salesAvg = value / salesTotal;
}
get {
return salesAvg;
}
}
However why is it necessary to create a property if a public member variable
will do. For example:
public int SalesTotal;
rather than
private int salesTotal;
public int SalesTotal
{
get {return salesTotal;}
set {salesTotal=value;}
}
standards. One thing we haven't agreed on is the use of properties in
classes vs using member variables. Now everyone knows that it is useful to
use a property when it has to do some further action on the data such as
private double salesAvg;
public double SalesAverage
{
set {
salesAvg = value / salesTotal;
}
get {
return salesAvg;
}
}
However why is it necessary to create a property if a public member variable
will do. For example:
public int SalesTotal;
rather than
private int salesTotal;
public int SalesTotal
{
get {return salesTotal;}
set {salesTotal=value;}
}