Information Technology Reference
In-Depth Information
reference types fragments the heap and slows you down. If you are creat-
ing types that are meant to store data values, value types are the way to go.
The decision to make a value type or a reference type is an important one.
It is a far-reaching change to turn a value type into a class type. Consider
this type:
public struct Employee
{
// Properties elided
public string Position
{
get ;
set ;
}
public decimal CurrentPayAmount
{
get ;
set ;
}
public void Pay( BankAccount b)
{
b.Balance += CurrentPayAmount;
}
}
This fairly simple type contains one method to let you pay your employ-
ees. Time passes, and the system runs fairly well. Then you decide that
there are different classes of Employees: Salespeople get commissions, and
managers get bonuses. You decide to change the Employee type into a class:
public class Employee2
{
// Properties elided
public string Position
{
get ;
set ;
}
 
Search WWH ::




Custom Search