How to pass an Enum to a Functon
- I have several Enums defined and I would like to know if anyone knows how to pass an Enum to a function.
Enum
eOne
eName
eAddress
eCity
End Enum
Enum eTwo
eDate
eEmailAddress
End Enum
''' <summary>
''' Routine that passes enum,
''' </summary>
''' <param name="EnumGoesHere"></param>
''' <remarks></remarks>
Public Sub PassEnum(ByVal EnumGoesHere)
Dim sqlString As String = Nothing
sqlString =
Me.LoadHdrEnum()
End Sub
''' <summary>
''' Routine that accepts enum.
''' </summary>
''' <param name="mode"></param>
''' <param name="sqlString"></param>
''' <param name="EnumGoesHere"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function LoadHdrEnum(ByVal mode As String, ByVal sqlString As String, ByVal EnumGoesHere) As String
Dim i As Int16 = 0
Dim holdString As String = Nothing
' Replace the Enum names with the numbers.
For Each enumType In [Enum].GetValues(GetType(EnumGoesHere))
Dim strMsgType As String = enumType.ToString()
sqlString = Replace(sqlString,
"hdr." & strMsgType, i)
i += 1
Next
Return sqlString
End Function
모든 응답
Pls. see:
Public Enum eOneeOne
eName
eAddress
eCity
End EnumEnum eTwo
eDate
eEmailAddress
End Enum
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PassEnum()
End Sub
Public Sub PassEnum()
Dim enumGoesHere1 As eOne = eOne.eAddressDim sqlString As String = Nothing
sqlString = Me.LoadHdrEnum("", "", enumGoesHere1)
End SubPublic Function LoadHdrEnum(ByVal mode As String, ByVal sqlString As String, ByVal EnumGoesHere As eOne) As String
Dim i As Int16 = 0
Dim holdString As String = Nothing' Replace the Enum names with the numbers.
For Each enumType In [Enum].GetValues(GetType(eOne))
If enumType = EnumGoesHere Then
Dim ii As Int32 = 0
End IfDim strMsgType As String = enumType.ToString()
sqlString = Replace(sqlString, "hdr." & strMsgType, i)i += 1
NextReturn sqlString
End Function
End Class

