© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
10 replies
hugi

How do I cast my enum to a list of custom object?

(yes I am aware of dictionary, but I want to use custom object in this case)
When I did it to dictionary I was doing the following:
var dict = Enum.GetValues(typeof(T))
   .Cast<T>().ToDictionary(t => (int)(object)t, t => getEnumString(t.ToString()));
var dict = Enum.GetValues(typeof(T))
   .Cast<T>().ToDictionary(t => (int)(object)t, t => getEnumString(t.ToString()));

But I wasn't able to figure out how to change that to cast to custom object instead, or do I just convert the dict above into custom object after? Is there a way to not do that?
custom object myObject: id: number, value: string
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

❔ How to cast to a generic of object?
C#CC# / help
3y ago
❔ How do I cast a byte to an enum MyEnum : byte
C#CC# / help
3y ago
✅ ToString of a list of an object
C#CC# / help
3y ago
❔ How to create a list of generic objects?
C#CC# / help
3y ago