Can someone help me translate this to LINQ? I have a string array (step.Variables), a dictionary (Parameters) and I want all pairs in Parameters where the key is in step.Variables.
This code works but I want to use LINQ and I cannot figure out how to translate:
parameters = new Dictionary<string, string>();
foreach (string variable in step.Variables)
{
if (Parameters.ContainsKey(variable))
{
parameters[variable] = Parameters[variable];
}
}
This is my best guess but get exeption:
var parameters = Parameters.ToDictionary(pair => step.Variables.Contains(pair.Key.ToString())).Select(pair => pair);
"System.ArgumentException: 'An item with the same key has already been added.'":