我會用位運算和.NET中長變量(以枚舉混合旗)
一個字段中db和方式更容易使用什麼用戶選擇播放
小樣本
Enum state As Long '64 enum maxium since long = 64 bits
ALABAMA = 1
ALASKA = 2
NEVADA = 4
ARIZONA = 8
ARKANSAS = 16
CALIFORNIA = 32
COLORADO = 64
CONNECTICUT = 128
DELAWARE = 256
'etc etc etc
End Enum
Module Module1
Sub Main()
Dim userselect As state = 0
Console.WriteLine("your checked box state")
Console.WriteLine("in this case im using the order of the enum for selecting")
Dim checkbox = New Boolean() {True, False, False, True, False, False, True, False, False}
For i = 0 To checkbox.Length - 1
userselect = CType(userselect + If(checkbox(i), (2^(i + 1)), 0), state)
Next
For Each s As state In [Enum].GetValues(GetType(state))
If (userselect And s) > 0 Then
Console.WriteLine("selected " & s.ToString)
End If
Next
Console.WriteLine("Value of userselect is " & userselect.ToString)
Console.ReadKey()
End Sub
End Module
OUTPUT:
selected NEVADA
selected ARIZONA
selected COLORADO
Value of userselect is 76
這是Windows窗體,ASP.NET或其他? – 2010-01-28 23:47:13
asP.net與VB.net代碼 – reger 2010-01-28 23:55:54
更新了我的答案 – Fredou 2010-01-29 00:06:44