Override the equals method of the function to determine whether the condition of the same class needs to be compared.

Source: Internet
Author: User

Recipientinfo. CS

 

Code
1 using system;
2 using system. Collections. Generic;
3 using system. text;
4
5 namespace leleapplication1
6 {
7 public class recipientinfo
8 {
9 // recipient class, including the email address and recipient's name
10 private string mailaddress;
11 private string name;
12
13 public recipientinfo (string mailaddress, string name)
14 {
15 this. mailaddress = mailaddress;
16 this. Name = Name;
17}
18
19 Public String mailaddress
20 {
21 get {return mailaddress ;}
22 set {mailaddress = value ;}
23}
24
25 public string name
26 {
27 get {return name ;}
28 set {name = value ;}
29}
30
31 public override bool equals (Object OBJ)
32 {
33 If (OBJ = NULL)
34 {
35 return false;
36}
37
38 If (obj. GetType () = typeof (recipientinfo ))
39 {
40 if (this. name. trim () = (recipientinfo) OBJ ). name. trim () & this. mailaddress. trim () = (recipientinfo) OBJ ). mailaddress. trim ())
41 {
42 return true;
43}
44 else
45 {
46 Return false;
47}
48}
49 else
50 {
51 return false;
52}
53}
54}
55}
56

 

Call page:

 

Code
1 List <recipientinfo> List = new list <recipientinfo> ();
2
3 recipientinfo info1 = new recipientinfo ("ss@ss.com", "name1 ");
4 recipientinfo info2 = new recipientinfo ("ss@ss.com", "name2 ");
5 recipientinfo info3 = new recipientinfo ("ss@ss.com", "name1 ");
6
7 List. Add (info1 );
8 list. Add (info2 );
9
10 if (list. Contains (info3 ))
11 {
12 console. writeline ("pinned ded ");
13}

 

Output result, encoded DED

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.