© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
15 replies
BenMcLean

❔ Casting range to bytes?

byte[] bytes = Enumerable.Range(0, 256).Cast<byte>().ToArray();
byte[] bytes = Enumerable.Range(0, 256).Cast<byte>().ToArray();
The result:
System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.Byte'.
System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.Byte'.

Why?
This should work!
Why doesn't this work!?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Replace Bytes To Another Bytes
C#CC# / help
2y ago
❔ Bytes to UInt64
C#CC# / help
3y ago
✅ Type Casting
C#CC# / help
4y ago
Casting object to enum class
C#CC# / help
2y ago