![](/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.