C
C#2y ago
reeeeeee

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
public static class StatusEnum
{
public const string Status1 = "1";
public static class StatusEnum
{
public const string Status1 = "1";
11 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
reeeeeee
reeeeeee2y ago
Any particular reason why that instead of direct enums?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
reeeeeee
reeeeeee2y ago
Okay cool, thanks!
ero
ero2y ago
const is better to show your intent But there's no functional difference
reeeeeee
reeeeeee2y ago
Thanks for info!
Becquerel
Becquerel2y ago
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
ero
ero2y ago
But the ToString call isn't amazing honestly You could do enum and use nameof
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jayy
Jayy2y ago
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View