Discussion on:
View:
Show:
Strongly typed is always much better. Declaring iEnvironment as an integer only makes for breakable code if the Environment variable type is changed later.
Strongly typed is always much better. Declaring iEnvironment as an integer only makes for breakable code if the Environment variable type is changed later.
In this example, the enumeration is named Environment, which is a preexisting class in the .Net framework. Isn't it a generally accepted best practice to not create your own variables/objects using the names of key words or objects previously established within the framework?
Combining enumeration and .NET capabilities, I would suggest the following changes to the original code. This will produce the same result
Dim myEnv As iEnvironment
MessageBox.Show(myEnv.Production.ToString() & ": " & myEnv.Production)
MessageBox.Show(myEnv.Dev.ToString() & ": " & myEnv.Dev)
Dim myEnv As iEnvironment
MessageBox.Show(myEnv.Production.ToString() & ": " & myEnv.Production)
MessageBox.Show(myEnv.Dev.ToString() & ": " & myEnv.Dev)
The code provided in the tip is suggested only for better understanding of enumaration and while there is certainly more than one way to get things done, this is provided as an example to functionality suggested in the tip.
- Keyboard Shortcuts:
- Prev
- Next
- Toggle

































