We have outdated character codes that we want to store as numbers in the new system. To increase readability and a general understanding of the code for developers doing the migration, I want to make Enums like this ...
Public Enum Status As Short
Open = AscW("O")
Closed = AscW("C")
Pending = AscW("P")
EnRoute = AscW("E")
End Enum
With this setting, the code will be readable (imagine If Record.Status = Status.Open), and yet the values will be stored in the database as small numbers, so they will be effective. However ... I am a VB.NET guy, but everyone wants to code in C #, so I need this structure in C #.
After Googling, I found that the overall .NET equivalent AscWis equal Convert.ToInt32("C"). When I try to use this operator in an enumeration, I get a constant expression compiler error.
How can I do this in C #? Is there a better way?
source
share