public void RemoveDuplicatesByName()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
List<Posting> postings = GetAllPostings();
postings.Sort();
![](/Images/OutliningIndicators/InBlock.gif)
for (int i = 1; i < postings.Count; i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (postings[i].Name == postings[i - 1].Name)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
postings.RemoveAt(i);
i--;
}
}
}
![](/Images/OutliningIndicators/None.gif)
public List<Posting> GetAllPostings()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
List<Posting> postings = new List<Posting>();
Posting posting;
posting = new Posting("post1", "2005-5-11");
postings.Add(posting);
posting = new Posting("post1", "2005-5-11");
postings.Add(posting);
posting = new Posting("post2", "2005-6-11");
postings.Add(posting);
posting = new Posting("post2", "2005-5-11");
postings.Add(posting);
posting = new Posting("post3", "2005-8-11");
postings.Add(posting);
posting = new Posting("post2", "2005-7-11");
postings.Add(posting);
posting = new Posting("post1", "2005-5-12");
postings.Add(posting);
posting = new Posting("post2", "2005-8-11");
postings.Add(posting);
return postings;
}
![](/Images/OutliningIndicators/None.gif)
public class Posting : IComparable<Posting>
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
private string name;
private string lastModifiedDate;
![](/Images/OutliningIndicators/InBlock.gif)
public Posting(string name, string lastModifiedDate)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.name = name;
this.lastModifiedDate = lastModifiedDate;
}
![](/Images/OutliningIndicators/InBlock.gif)
public string Name
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return name; }
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ name = value; }
}
![](/Images/OutliningIndicators/InBlock.gif)
public string LastModifiedDate
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return lastModifiedDate; }
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ lastModifiedDate = value; }
}
![](/Images/OutliningIndicators/InBlock.gif)
public int CompareTo(Posting other)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return (String.Compare(this.Name, other.Name));
}
}
posted on
2006-05-12 13:14
fengzhimei
阅读(
894)
评论()
编辑
收藏
举报