imagine I have a list
List<String> B
and a dictionary
Dictionary<String, int> A
How can I return a Dictionary<String, int> that filtered from A with the keys in B by using Linq?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Easy, using
Whereto filter the key/value pairs, and thenToDictionaryto build a new dictionary.If you have a lot of entries, you may want to create a
HashSet<string>first:That will make it faster to test each key.