使用Dictionary键查找列表obj?

时间:2013-06-07 11:04:54

标签: c# list dictionary

我引用了存储在List和Dictionary中的许多对象。是否有方法通过提供字典中的键值来查找和更改列表中对象的值?

public bool isChanged(List<obj> original, List<obj> recent)
{
  bool isChanged = false;

  Dictionary<long, obj> originalPK = new Dictionary<long, obj>();
  Dictionary<long, obj> recentPK = new Dictionary<long, obj>();
  Dictionary<long, obj> deletedentries = new Dictionary<long, obj>();
  Dictionary<long, obj> newentries = new Dictionary<long, obj>();

  // used foreach to copy obj ref in original into originalPK
  // used foreach to copy obj ref in recent into recentPK
  // placed refs to identical objs within originalPK and recentPK into existinboth
  // placed refs from within originalPK that weren't in recentPK into deletedentries
}

我没有使用deletedentries中的键值将refs删除为原始的objs,而是希望使用deletedentries的键/值搜索original,然后更改原始属性。像这样:

foreach(long key in deletedentries.Keys)
{
  original[key].isActive = "false";
}

0 个答案:

没有答案