Why does LINQ query throw an exception when I attempt to get a count of a type
问题 public readonly IEnumerable<string> PeriodToSelect = new string[] { "MONTH" }; var dataCollection = from p in somedata from h in p.somemoredate where h.Year > (DateTime.Now.Year - 2) where PeriodToSelect.Contains(h.TimePeriod) select new { p.Currency, h.Year.Month, h.Value }; Can someone tell me why an exception is thrown when at the following line of code? int count = dataCollection.Count(); This is the exception: System.NullReferenceException: Object reference not set to an instance of an