0
我想僅使用數字0 - 3之間的整數參數,我該怎麼做?創建一個整數參數,其值僅在0 - 3之間
我用枚舉試過,但它不允許的起始編號是這樣
Public Enum Octet_Num As Integer
0
1
2
3
End Enum
下面的代碼將工作的一個整數,但它似乎不練的好編碼標準?
Public Enum Octet_Num
first_octet
second_octet
third_octet
fourth_octet
End Enum
Function Get_Octet_IPAdd(octet_num As Usage_Get_Octet_IPAdd)
Dim octet As Integer
If octet_num = Octet_Num.first_octet Then
Octet = 0
End If
If octet_num = Octet_Num.second_octet Then
Octet = 1
End If
If octet_num = Octet_Num.third_octet Then
Octet = 2
End If
If octet_num = Octet_Num.fourth_octet Then
Octet = 3
End If
Dim fourthOctet As String = Format(IPAddress.Parse("192.168.1.130").GetAddressBytes(3), "000")
Return fourthOctet
End Function
枚舉被用作索引正是用於此目的的 – Fabio