var result = from pKey in _properties.Keys where _expectations.ContainsKey(pKey) let e = _expectations[pKey] select e;
This is more efficient than combining, because it uses key searching in _expectations . It could be improved a bit using this extension method:
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) where TValue : class { TValue value; if (dictionary.TryGetValue(key, out value)) return value; return null; } var result = from pKey in _properties.Keys let e = _expectations.GetValueOrDefault(pKey) where e != null select e;
(he avoids searching for the key twice)
source share