Re: [問題] listbox裡面如何刪除重複元素
※ 引述《sinyun (sinyun)》之銘言:
: 小妹我寫了一個程式,會把資料顯示listbox裡面,可是listbox裡面有相同的資料
: 我想要設定一個label,按一下以後就會把相同的資料給刪掉 只留下一個 也就
: 是不出現重複的資料拉!! 不知道該怎麼寫!!
private void button2_Click(object sender, EventArgs e)
{
List<string> temp = new List<string> {};
for (int i = 0; i < listBox1.Items.Count; i++)
{
string item = listBox1.Items[i].ToString();
if (temp.Contains(item))
{
listBox1.Items.RemoveAt(i);
i -= 1;
}
else
{
temp.Add(item);
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.233.175.175
※ 編輯: a761007 來自: 125.233.175.175 (07/22 15:09)
→
07/22 15:12, , 1F
07/22 15:12, 1F
→
07/22 15:13, , 2F
07/22 15:13, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章