PART I
C h a p t e r 1 8 :
G e n e r i c s
507
PART IPART I
// A base class that stores a name and phone number.
class PhoneNumber {
public PhoneNumber(string n, string num) {
Name = n;
Number = num;
}
// Auto-implemented properties that hold a name and phone number.
public string Number { get; set; }
public string Name { get; set; }
}
Next, you create two classes that inherit
PhoneNumber
:
Friend
and
Supplier
. They are
shown here:
// A class of phone numbers for friends.
class Friend : PhoneNumber {
public Friend(string n, string num, bool wk) :
base(n, num)
{
IsWorkNumber = wk;
}
public bool IsWorkNumber { get; private set; }
// ...
}
// A class of phone numbers for suppliers.
class Supplier : PhoneNumber {
public Supplier(string n, string num) :
base(n, num) { }
// ...
}
Notice that
Do'stlaringiz bilan baham: |