In vb.net, I got an Enum defined As Integer:
Enum enUtilityTypeDetailStudentEntryWorkflow As Integer
enUTDSEW_Default = 379
enUTDSEW_ApplicantRecordBook = 380
End Enum
I would like to assign the Enum directly to a variable but it does not work.
EntryWorkflowLookUpEdit.EditValue = enUtilityTypeDetailStudentEntryWorkflow.enUTDSEW_Default
I ended up using a CType and converting it to an Integer.
EntryWorkflowLookUpEdit.EditValue = CType(enUtilityTypeDetailStudentEntryWorkflow.enUTDSEW_Default, Integer)
This works but it adds a lot of noise to the code and it seems like the Enum is already defined as an Integer, making me think, why do I have to assign it again?
Is there other ways to accomplish this without all the noise?
I know I am missing something here.
Thanks a bunch.
The enum is defined as using an integer as its underlying type.
It’s a good thing that this is an explicit conversion IMO, because it means you don’t accidentally end up using an enum value where you really meant to just use a straight integer. The point of enums is to effectively have different “views” of numbers – and changing which “view” you’re using should be explicit.
I would expect there to be relatively few such conversions in most codebases.
If this becomes a significant issue for you, you could always write an extension method of
ToInt32or something like that, which just performed the cast.Personally if I were trying to reduce the noise in this code, I’d try to find a shorter name than
enUtilityTypeDetailStudentEntryWorkflow– and one which conformed with the .NET naming conventions, at the same time.