I came across a strange Linq behavior: with two linq expressions that might seem identical, I have different results! If I loop once, I get the same result, but find nothing above.
Here is the code:
Dictionary<String, String> mainDico = new Dictionary<String, String>(); mainDico.Add("key1", "value1"); mainDico.Add("key2", "value2"); List<Dictionary<String, String>> ls = new List<Dictionary<String, String>>(); Dictionary<String, String> fistDico = new Dictionary<String, String>(); fistDico.Add("key1", "value1"); fistDico.Add("key2", "value2"); Dictionary<String, String> secondDico = new Dictionary<String, String>(); secondDico.Add("key1", "other"); secondDico.Add("key2", "other"); ls.Add(fistDico); ls.Add(secondDico); IEnumerable<Dictionary<String, String>> failQuery = from p in ls select p; IEnumerable<Dictionary<String, String>> successfulQuery = from p in ls select p; String[] items = new String[] { "key1","key2" };
source share