© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
9 replies
DaVinki

✅ Using Linq's Cast Method

I've never been able to get it to not warn and throw errors except for one, maybe two times. It is always warning me even if the cast is what I want and has thrown over it before. These casts are trivial casts like casting an int to another value type like long or char. I also have never really bothered asking about it since I just do
.Select(o => (T)o)
.Select(o => (T)o)
in the end.

Say I had an IEnumerable of random ints. Why can't I just do
.Cast<char>()
.Cast<char>()
if I wanted to cast them into chars instead of doing
.Select(i => (char)i)
.Select(i => (char)i)
? If I can, what am I missing to do so?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ EFCore LINQ methods
C#CC# / help
3y ago
❔ Calling extensions method in linq query
C#CC# / help
3y ago
✅Shuffling db results using LINQ.
C#CC# / help
2y ago
Get max index using linq
C#CC# / help
3y ago