![](/img/trans.png)
[英]How to find the key of a dictionary when the value is a list of objects in C#?
[英]Find out Key of c# Dictionary when Any() returns true
从下面的代码中,我总会知道是否有任何DatFiles不同步。 但是如何获得哪一个呢?
bool isNotinSync = DatFileListDictioanry.Any(t => IsThisDatFileNotInSync(t.Key)) // I want a key or Pair here!
我知道可以使用简单的for循环并检查所有对值来实现。 但是有更好的东西吗?
以下应该会有所帮助:
如果您只需要第一个/ default条目
DatFileListDictioanry.FirstOrDefault(t => IsThisDatFileNotInSync(t.Key))
如果您需要完整的清单,请:
DatFileListDictioanry.Where(t => IsThisDatFileNotInSync(t.Key))
尝试这个:
DatFileListDictioanry.Where(t => IsThisDatFileNotInSync(t.Key)).FirstOrDefault()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.