1

我引用了存储在列表和字典中的许多对象。有没有一种方法可以通过提供字典中的键值来查找和更改列表中对象的值?

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
}

我不想使用已删除条目的键值来删除原始对象的引用,而是想使用已删除条目的键/值搜索原始对象,然后更改原始对象的属性。像这样的东西:

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

0 回答 0