16

Is there a way to create a constant shared array? The ovbious way :

Shared Const GX() As String = {"GS", "GP"}

Is not working, it says you can't use shared and const together.

If you use only const it says you can't declare a contant array in a class.

Thanks in advance

Peter
  • 37,042
  • 39
  • 142
  • 198
  • you can create constant variable at application level and have access to that variable in any class inside your application – Epsil0neR Nov 12 '13 at 09:39
  • 1
    If you already know the values to add in the array, why don't you use an `enumeration`? – Nadeem_MK Nov 12 '13 at 09:40
  • Please, type `Const GX() As String` and read the error message you get. As suggested above, you can use an `Enum`; an array of constants goes against the basic `Const` rules. – varocarbas Nov 12 '13 at 09:46

3 Answers3

23

I don't think it's possible. An alternative would be to use ReadOnly

Public Shared ReadOnly GX() As String = {"GS", "GP"}
the_lotus
  • 12,668
  • 3
  • 36
  • 53
3

Sadly, you are not able to use Arrays in constants...

See here for details...

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
2

You cannot use the Shared modifier in a Const Statement (Visual Basic), but constants are implicitly shared. Similarly, you cannot declare a member of a module or an interface to be Shared, but they are implicitly shared. Read this MSDN Document. You can not use shared and constant in same time

Sathish
  • 4,419
  • 4
  • 30
  • 59