如何刪除使用HashSet的重複,或者如果你有更好的想法,請讓我知道,但到目前爲止,這是我在做什麼...使用HashSet的刪除重複
我試圖消除重複和下面的代碼就是我用....
HashSet<DropDownListClass> hashSetTopics = new HashSet<DropDownListClass>();
foreach (XmlNode node in topicNodes)
{
string topicId = node.Attributes["TopicId"].Value;
string topicName = node.Attributes["TopicName"].Value;
hashSetTopics.Add(new DropDownListClass { Id = topicId, Name = topicName });
}
the below code does removes the duplicates but the problem with the below is that i need a way to attach the id with name... at the end i am binding to dropdownlist.
HashSet<string> hashSetTopics1 = new HashSet<string>();
foreach (XmlNode node in topicNodes)
{
string topicId = node.Attributes["TopicId"].Value;
string topicName = node.Attributes["TopicName"].Value;
hashSetTopics1.Add(topicName });
}
DropDownList1.DataSource = hashSetTopics; /hashSetTopics1
DropDownList1.DataBind();
public class DropDownListClass
{
public string Id { get; set; }
public string Name { get; set; }
}
'從Hashset中刪除重複項。 Man,Hashset不能有重複,這就是它的重點。 –
@Darin我想他是問如何使用Hashset刪除重複作爲一種做法,而不是從Hashset中刪除重複。 –
但是他又一次從另一個哈希集合中做出來,所以我看到了這個問題。 :) –