vb.net 中的常量共享数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19925573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Constant Shared array in vb.net
提问by the_lotus
Is there a way to create a constant shared array? The ovbious way :
有没有办法创建一个常量共享数组?明显的方式:
Shared Const GX() As String = {"GS", "GP"}
Shared Const GX() As String = {"GS", "GP"}
Is not working, it says you can't use shared and const together.
不工作,它说你不能一起使用 shared 和 const 。
If you use only const it says you can't declare a contant array in a class.
如果你只使用 const 它说你不能在一个类中声明一个常量数组。
Thanks in advance
提前致谢
回答by the_lotus
I don't think it's possible. An alternative would be to use ReadOnly
我不认为这是可能的。另一种方法是使用 ReadOnly
Public Shared ReadOnly GX() As String = {"GS", "GP"}
回答by Martin Milan
回答by Sathish
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. Readthis MSDN Document. You can not use shared and constant in same time
不能在 Const 语句 (Visual Basic) 中使用 Shared 修饰符,但常量是隐式共享的。同样,您不能将模块或接口的成员声明为共享,但它们是隐式共享的。阅读此 MSDN 文档。不能同时使用 shared 和 constant

