Asked
Active
Viewed 544 times
-4

41686d6564 stands w. Palestine
- 19,168
- 12
- 41
- 79

PrasadK
- 25
- 5
-
2Thank you for making my life more difficult by posting a picture of your code instead of the actual code. I scrolled up to copy your code to post into my answer and I couldn't because you didn't post the code. DO NOT post pictures of code or errors. They are text. Post the text. If a screenshot can provide additional clarity then post an ADDITIONAL screenshot. NEVER post a screenshot alone. – jmcilhinney Aug 22 '18 at 08:01
-
Also, what you do is up to you but it is just so pointless and downright silly to prefix `Enum` type names with "e". Hungarian Notation is pointless now anyway and it was never intended to extend to something like that to begin with. Do you suddenly get all confused when using an `Enum` from the .NET Framework because they don't have that prefix? If you can use those types without a prefix, why do you need one on your own types? – jmcilhinney Aug 22 '18 at 08:04
-
Possible duplicate of [Option Strict On disallows late binding with system.array](https://stackoverflow.com/questions/6749288/option-strict-on-disallows-late-binding-with-system-array) – TnTinMn Aug 22 '18 at 13:39
-
Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*). – Peter Mortensen Oct 31 '22 at 10:08
1 Answers
3
You should pretty much NEVER declare something as type Array
. If you are creating a String
array then declare that:
Dim itemNames As String() = System.Enum.GetNames(GetType(Configuration.eSystemType))
Of course, given that Enum.GetNames
has a return type of String()
, you could just use type inference:
Dim itemNames = Enum.GetNames(GetType(Configuration.eSystemType))
I've also dropped the superfluous System
namespace qualifier there.
Perhaps you were fooled by the fact that Enum.GetValues
is declared as type Array
. I did say "pretty much never". There are rare cases where it's required but you, as an application developer, will almost certainly never have to do it. The array returned is of the type you specified so you should cast as that type:
Dim itemValues = DirectCast(Enum.GetValues(GetType(Configuration.eSystemType)),
Configuration.eSystemType())
The ListItem
constructor still requires two String
arguments though, so you still need to convert the Configuration.eSystemType
values to Strings
:
Dim item As New ListItem(itemNames(i), itemValues(i).ToString())

jmcilhinney
- 50,448
- 5
- 26
- 46