On Mon, 13 Oct 2003 00:25:17 +0930, "Shayne H"
<shaynehATlycos SPAMGOTOHELLcoD OTuk> wrote:
What is the best way to enumerate a grouping of strings?
The way I have been doing it is:
Public Enum PlatformID
Unknown
Win16
Win32
Win32NT
WinCE
End Enum
I'm guessing you're not talking about System.Platform ID.
Private Shared sPlatform() As String = { _
"Unknown", _
"Microsoft Windows 16-bit", _
"Microsoft Windows 32-bit", _
"Microsoft Windows NT 32-bit", _
"Microsoft Windows CE"}
I don't suppose this is what you're after...
Dim oPlatformID As PlatformID
oPlatformID = PlatformID.Win3 2
MsgBox( oPlatformID.ToS tring() )
If internationalis ation is an issue, then you should use resources.
(Unlikely, as "Microsoft Windows CE" is the same in most languages)
If you require spaces (etc.) to be in the name, the best way is to
implement a singleton class that wraps up a StringDictionar y
(initialised in its constructor) - see below.
And if you fancy being a pedant, you should implement a Platform class
instead of an enum, a PlatformCollect ion of some sorts (an inherited
HybridDictionar y is a good one), a PlatformFactory object to serialise
the objects from resources (and implement the GetCurrentPlatf orm
method)... and be sure to implement IComparable and IEnumerable on the
Platform and PlatformCollect ion respectively. Infact, inherit your own
IPlatformEnumer able so that you can iterate though any other ADT
collections you decide to implement. Ooh! And don't forget to
implement an IPlatform interface in case anyone wants to alter the
implementation of a Platform... ;]
More seriously, the following allows for future extension (and the
model can be applied to other things... for your reference)
Public Class PlatformFactory
Private Shared mPlatformMap As HybridDictionar y
Shared Sub New()
mPlatformMap = New HybridDictionar y()
mPlatformMap.Ad d(PlatformID.Un known, "Unknown")
mPlatformMap.Ad d(PlatformID.Wi n16, "Microsoft Windows 16-bit")
' etc...
End Sub
Public Shared Function GetName(ByVal oPlatformID As PlatformID) _
As String
Return mPlatformMap(oP latformID)
End Function
End Class
Rgds,