我正在尝试将可选的Enum传递给函数,但无法正确获取语法。我正在尝试以下方法:
Public Function MyFunction(ByVal TestCode As String, Optional ByVal Columns As [Enum] = MyEnumName.EnumVariable) As Boolean
也尝试过:
Public Function MyFunction(ByVal TestCode As String, Optional ByVal Columns As [Enum] = MyEnumName) As Boolean
并收到错误消息
“从”MyEnumName“到”System.Enum“的转换不能出现在常量表达式中”
是否可以使用可选的枚举或我做错了什么?
提前致谢
答案 0 :(得分:3)
在处理Enum
时,您必须指定给定名称而不是[Enum]
作为类型。示例代码:
Public Enum MyEnumName
val1
val2
End Enum
Public Function MyFunction(ByVal TestCode As String, Optional ByVal Columns As MyEnumName = MyEnumName.val1) As Boolean
End Function