You can *sorta* use Enums interchangably with their base types (int for example), but you do have to Cast. At first, I was really bothered by this but now I dont mind. In fact, its saved my behind a few times. Case in point, in VB6 you could interchangably use the enum or an Integer/Long. Unfortunately, that meant you had to
manually check each value to ensure it was a proper Enum value before using it. I *hated* that - it usually meant creating two constants to define the upper/lower valid values for an Enum to keep the code "clean".
While you have to cast an enum to an int now, I think it promotes much safer (or "strict") coding. The only downside Ive seen is forgetting to cast the enum when assigning to a variable declared as object - youll get no warning but its probably not what you want to do. For example, we define all system-dependent lookup values as enums so that we can easily find them in code. When using one of these enums in a DataSet (where each columns value is type object), you can put in the Enum itself without casting. If you try and send that DataSet to a Webservice, youll get an error because the Enum doesnt exist on the other end (the serializer is nice enough to put the Enum in the DataSet as itself, not as an integer value).
Heres some old VB6 code, for those interested, that shows just how BAD Enums could be:
Code:
Public Enum Testing
a = 1
b = 2
c = 3
End Enum
Private Sub Form_Load()
Dim a As Testing
a = Testing.b
Debug.Print a
a = 8
Debug.Print a
Test c
Test 19
End Sub
Private Sub Test(TestVal As Testing)
Dim enumVal As Testing
enumVal = TestVal
Debug.Print enumVal
End Sub
This prints:
2
8
3
19
Obviously, the 8 and the 19 should NEVER have been allowed to be assigned since the variables are explicitly defined to be of type Testing (the enum). Arggh.... shame on you, VB6.
-Nerseus