I have some code that takes a value (of type object) and tries to cast it to an IEnumerable of ints and uints like so:
var idList = value as IEnumerable<int>;
var uintList = value as IEnumerable<uint>;
When the value is initialized this way:
uint number = 1;
object value = new []{ number };
both idList and uintList have values, but calling idList.ToList() results in an ArrayTypeMismatchException
. However, when the value is generated with new List<uint>{ number }
, idList is null as expected.
Additionally, calling var idList = value as IEnumerable<int>;
in the immediate window in VS 2015 returns null as I would expect, even when the value was generated with a collection initializer.
.Net fiddle reproducing the error here.
What's going on here?