Why can't I assign List<int> to IEnumerable<object> in .NET 4.0
问题 I try to do this: IEnumerable<object> ids = new List<string>() { "0001", "0002", "0003" }; it works great! But when I try to do this: IEnumerable<object> intIds = new List<System.Int32>() { 1, 2, 3 }; Visual Studio tells me: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?) Why is that? 回答1: int is a value type and can only be boxed to object - it doesn't inherit from object .