i have a Generic.Collection.List and Generic.Collection.Dictionary like
List<String> MyList
Dictionary<String, List<String>> MyDictionary
I need to filter the MyDictionary based on the intes in the MyList i.e if an item of MyList is in the value of MyDictionary, then that item will be added into MyFilteredDictionary.
Dictionary<String, List<String>> MyFilteredDictionary
Now i’m doing this by using `for-foreach loop, like
for (int l_nIndex = 0; l_nIndex < MyList.Count; l_nIndex++)
{
foreach (KeyValuePair<String, List<String>> l_objKeyValuePair in MyDictionary)
{
if (l_objKeyValuePair.Value.Contains(MyList[l_nIndex]) == true)
{
MyFilteredDictionary.Add(l_objKeyValuePair.Key, l_objKeyValuePair.Value);
break;
}
}
}
How to do the same using `Lambda Expression?
1 Answer