.


:




:

































 

 

 

 


.




NotFoundException Exception . */

public NotFoundException () base() { }

public NotFoundException(string str): base(str) { }

Public NotFoundException (

string str,Exception inner): base(str, inner) { } protected NotFoundException(

System.Runtime.Serialization.Serializationlnf si,

System.Runtime.Serialization.StreamingContext sc): base (si, sc) { }

}

// , , class PhoneNumber {

public PhoneNumber(string n, string num) {

Name = n;

Number = num;

}

public string Number { get; set; } public string Name { get; set; }

}

// , class Friend: PhoneNumber {

public Friend(string n, string num, bool wk): base(n, num)

IsWorkNumber = wk;

}

public bool IsWorkNumber { get; private set; }

 

//...

}

// , class Supplier: PhoneNumber {

public Supplier(string n, string num): base(n, num) { }

//...

}

// PhoneNumber. class EmailFriend {

//...

}

// PhoneList , // , PhoneNumber. class PhoneList<T> where T: PhoneNumber {

T[] phList; int end;

public PhoneList() { phList = new T[10]; end = 0;

}

// , public bool Add(T newEntry) { if(end == 10) return false;

phList[end] = newEntry; end++; return true;

}

// , public FindByName(string name) {

for(int i=0; i<end; i++) {

// , Name // PhoneNumber, // , if(phList[i].Name == name) return phList[i];

}

// , throw new NotFoundException();

// , public FindByNumber(string number) { for(int i=0; i<end; i++) {

// " , // Number PhoneNumber, // , if(phList[i].Number == number) return phList[i];

}

// . throw new NotFoundException ();

}

//...

}

// , class UseBaseClassConstraint { static void Main() {

// , // Friend PhoneNumber.

PhoneList<Friend> plist = new PhoneList<Friend>(); plist.Add(new Friend("", "555-1234", true)); plist.Add(new Friend("", "555-6756", true)); plist.Add(new Friend("", "555-9254", false));

try {

// .

Friend frnd = plist.FindByName("");

Console.Write(frnd.Name + ": " + frnd.Number);

If(frnd.IsWorkNumber)

Console.WriteLine(" ()"); else

Console.WriteLine ();

} catch(NotFoundException) {

Console.WriteLine("He ");

}

Console.WriteLine();

// , // Supplier PhoneNumber.

PhoneList<Supplier> plist2 = new PhoneList<Supplier>(); plist2.Add(new Supplier(" Global Hardware", "555-8834")); plist2.Add(new Supplier (" Computer Warehouse", "555-9256")); plist2.Add(new Supplier(" NetworkCity", "555-2564")); try {

// . Supplier sp = plist2.FindByNumber("555-2564");

Console.WriteLine(sp.Name + ": " + sp.Number);

} catch(NotFoundException) {

Console.WriteLine("He ");

}

// ,

// EmailFriend PhoneNumber.

// PhoneList<EmailFriend> plist3 =

// new PhoneList<EmailFriend>(); // !

}

}

.

: 555-6756 ()

NetworkCity: 555-2564

. , IsWorkNumber PhoneList. , , IsWorkNumber Friend, PhoneNumber, , PhoneList.

, . , . -, . -, , . , , , , .

, where:

where : _

, _ . . , .

, , . PhoneNumber I PhoneNumber, Friend Supplier.

// , using System;

// , ,

// , class NotFoundException: Exception {

/* Exception.

. NotFoundException Exception . */

public NotFoundException(): base() { }

public NotFoundException(string str): base(str) { }

Public NotFoundException(

string str,Exception inner): base(str, inner) { }

protected NotFoundException (





:


: 2016-12-03; !; : 374 |


:

:

, .
==> ...

1473 - | 1384 -


© 2015-2024 lektsii.org - -

: 0.014 .