我有一本字典,您可以通过在列表框中搜索来添加卡片,但现在我希望能够在用户按下按钮时从字典中删除该项目这是我用来向字典添加值的代码
if (!m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Exists(banListCard => banListCard.ID == Program.CardData[cardid].Id))
{ m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Add(
new BanListCard { ID = Program.CardData[cardid].Id, Banvalue = 0, Name = Program.CardData[cardid].Name });
}
我不会发布所有代码,因为它太长了我用来删除项目的代码
var list = (ListBox) sender;
if (list.SelectedIndex != -1)
{
int cardid = Int32.Parse((string)list.SelectedItem.ToString());
if (m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Exists(banListCard => banListCard.ID == Program.CardData[cardid].Id))
{
m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Remove();
list.Items.RemoveAt(list.SelectedIndex);
}
}
但我不知道在 remove 的括号中放入什么来查找值哦,它需要查找 ID 值