Enum vs string const class
I have a string property, which will accept some kind of enum
Is it better to have a proper
Enum
and call ToString()
when setting the property (public enum StatusEnum
and set it p1 = StatusEnum.Status1.ToString()
), or should I have a static class which will have constants, something like this
11 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Any particular reason why that instead of direct enums?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Okay cool, thanks!
const is better to show your intent
But there's no functional difference
Thanks for info!
it's worth noting you can actually define extension methods for enums
which you can use to tie strings directly to them
might be useful
But the ToString call isn't amazing honestly
You could do enum and use nameof
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
theres no good way to do this
c# doesnt have DUs/tagged enums sadly
so whenever u are using an enum on the boundaries of a program its going to be awkward
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View