Why can't I assign List to IEnumerable<object> in .NET 4.0

后端 未结 4 1473
慢半拍i
慢半拍i 2020-12-11 02:44

I try to do this:

IEnumerable ids = new List() { \"0001\", \"0002\", \"0003\" };


it works great!

But wh

4条回答
  •  我在风中等你
    2020-12-11 03:09

    int is a value type and can only be boxed to object - it doesn't inherit from object. Since you're using an IEnumerable anyway, this should work:

    IEnumerable intIds = new List() { 1, 2, 3 };
    

    提交回复
    热议问题