var keyword not always working?
问题 C#, VS 2010. Somebody, please explain why I can't use var in my code below! var props = TypeDescriptor.GetProperties(adapter); // error CS1061: 'object' does not contain a definition for 'DisplayName' foreach (var prop in props) { string name = prop.DisplayName; } // No error foreach (PropertyDescriptor prop in props) { string name = prop.DisplayName; } TypeDescriptor.GetProperties returns a PropertyDescriptorCollection with instances of PropertyDescriptor . Why can't the compiler see this?