Tuesday, August 23, 2005

my herd
Hi all : I have a herd of sheep genetically lazy. There just only one birth from one generation to another. To know how many sheeps in the herd for the x teen generation I just have to ++ the preceding number. So to perform this computing in a nice way I have overloaded the ++ operator for my HerdOfSheep class: it looks like this:


namespace SheepOperatorsSample
{
public class HerdOfSheep
{
private int number;
public int Number
{
get
{
return number;
}
set
{
number = value;
}
}
public static HerdOfSheep operator ++ (HerdOfSheep myHerd)
{
myHerd.Number++;
return myHerd;
}

}
}

0 Comments:

Post a Comment

<< Home