RecipientInfo.cs
1
using System;2
using System.Collections.Generic;3
using System.Text;4

5
namespace ConsoleApplication16


{7
public class RecipientInfo8

{9
//收件人的类,包含邮件地址和收件人的姓名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 MailAddress20

{21

get
{ return mailAddress; }22

set
{ mailAddress = value; }23
}24

25
public string Name26

{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
else45

{46
return false;47
}48
}49
else50

{51
return false;52
}53
}54
}55
}56

调用页面:
1
List<RecipientInfo> list = new List<RecipientInfo>();2

3
RecipientInfo info1 = new RecipientInfo("[email protected]", "name1");4
RecipientInfo info2 = new RecipientInfo("[email protected]", "name2");5
RecipientInfo info3 = new RecipientInfo("[email protected]", "name1");6

7
list.Add(info1);8
list.Add(info2);9

10
if (list.Contains(info3))11

{12
Console.WriteLine("included");13
}
输出结果,included
浙公网安备 33010602011771号