我正在處理的應用程序有很多枚舉。如何存儲枚舉值的字符串描述?
這些值通常從應用程序中的下拉列表中選擇。
什麼是普遍接受的方式來存儲這些值的字符串描述?
這裏是手頭上的當前問題:
Public Enum MyEnum
SomeValue = 1
AnotherValue = 2
ObsoleteValue = 3
YetAnotherValue = 4
End Enum
下拉應該有以下選擇:
Some Value
Another Value
Yet Another Value (Minor Description)
並非所有符合枚舉的名稱,(次要介紹的一個是一個例子),並不是所有的枚舉值都是-current-值。有些僅保留用於向後兼容性和顯示目的(即打印輸出,而不是表單)。
這導致了下面的代碼情況:
For index As Integer = 0 To StatusDescriptions.GetUpperBound(0)
' Only display relevant statuses.
If Array.IndexOf(CurrentStatuses, index) >= 0 Then
.Items.Add(New ExtendedListViewItem(StatusDescriptions(index), index))
End If
Next
這只是好像這是可以做到更好,我不知道怎麼樣。
感謝您的來源鏈接,爲進一步擴展此功能提供了很好的建議。 – 2010-07-06 18:12:09