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?
int
is a value type and can only be boxed to object
- it doesn't inherit from object
. Since you're using an IEnumerable<object>
anyway, this should work:
IEnumerable intIds = new List<int>() { 1, 2, 3 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With