例如,我有一个名为 Temp 的类,然后我使用IList<Temp>
. 填充后,IList<Temp>
我创建了一个字典并为每个对象分配了一个 int 键。我的问题是,如何从 IList 和字典中删除名称为 b 和键值为“2”的 temp_value?
class Temp
{
public string name { get; set; }
public Temp(string n)
{
this.name = n;
}
}
主要的
class Program
{
static void Main(string[] args)
{
IList<Temp> temp_value = new List<Temp>();
temp_value.Add(new Temp("a")
{
name = "a",
});
temp_value.Add(new Temp("b")
{
name = "b",
});
temp_value.Add(new Temp("b")
{
name = "b",
});
Dictionary<int, Temp> dic = new Dictionary<int, Temp>();
for (int i = 0; i < temp_value.Count; i++)
{
dic.Add(i, temp_value[i]);
}
}
}