VB Brackets in Enum?

和自甴很熟 提交于 2020-01-04 14:13:25

问题


I'm finding this in some legacy code and just curious what the brackets are for?

Public Enum myEnum
    none = 0
    abc = 2
    def = 4
    ghi= 6
    [jkl] = 8
    mno = 9
End Enum

回答1:


They're not needed in the example you provided, which I assume you have obscured, but the brackets let you specify a name for an enum item that would otherwise conflict with a reserved word.




回答2:


Brackets are usually used when you want to use a keyword for a variable, classname, function name, or something else where using a keyword would usually be not allowed. Here is a list of the vb.net keywords.



来源:https://stackoverflow.com/questions/778618/vb-brackets-in-enum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!