Suppose I have an IEnumerable<int>
and I want these to be converted into their ASCII-equivalent characters.
For a single integer, it would just be (char)i
, so there's always collection.Select(i => (char)i)
, but I thought it would be a tad cleaner to use collection.Cast()
.
Can anyone explain why I get an InvalidCastException
when I use collection.Cast<char>()
but not with collection.Select(i => (char)i)
?
Edit: Interestingly enough, when I call collection.OfType<char>()
I get an empty set.