473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Best practice for enumerating string constants

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

Private Shared sPlatform() As String = { _
"Unknown", _
"Microsoft Windows 16-bit", _
"Microsoft Windows 32-bit", _
"Microsoft Windows NT 32-bit", _
"Microsoft Windows CE"}

Private Shared Function PlatformToString(ByVal platform As
OSInfo.PlatformID) As String
Return sPlatform(platform)
End Function

Is there a better way to do this?
I feel that the strings should be constants rather than stored in a private
array field, but I cannot see a way other than a really long select case
statement.

--
Thanks for any help,
Shayne H
Jul 21 '05 #1
2 3949
Use the ToString() method on the object, with the "g" or "f" format
specifier.

Dim x as PlatformID
x = PlatformID.Win16
Console.Writeline(x.ToString("f"))

should print "Win16" to the screen
"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:OV**************@TK2MSFTNGP09.phx.gbl...
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

Private Shared sPlatform() As String = { _
"Unknown", _
"Microsoft Windows 16-bit", _
"Microsoft Windows 32-bit", _
"Microsoft Windows NT 32-bit", _
"Microsoft Windows CE"}

Private Shared Function PlatformToString(ByVal platform As
OSInfo.PlatformID) As String
Return sPlatform(platform)
End Function

Is there a better way to do this?
I feel that the strings should be constants rather than stored in a private array field, but I cannot see a way other than a really long select case
statement.

--
Thanks for any help,
Shayne H

Jul 21 '05 #2
Use the ToString() method on the object, with the "g" or "f" format
specifier.

Dim x as PlatformID
x = PlatformID.Win16
Console.Writeline(x.ToString("f"))

should print "Win16" to the screen
"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:OV**************@TK2MSFTNGP09.phx.gbl...
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

Private Shared sPlatform() As String = { _
"Unknown", _
"Microsoft Windows 16-bit", _
"Microsoft Windows 32-bit", _
"Microsoft Windows NT 32-bit", _
"Microsoft Windows CE"}

Private Shared Function PlatformToString(ByVal platform As
OSInfo.PlatformID) As String
Return sPlatform(platform)
End Function

Is there a better way to do this?
I feel that the strings should be constants rather than stored in a private array field, but I cannot see a way other than a really long select case
statement.

--
Thanks for any help,
Shayne H

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shayne H | last post by:
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
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
by: Ronald S. Cook | last post by:
It seems to make more sense to separate app settings (e.g. global variables, constants that the development team would control) from web settings (e.g. database connection strings) that the...
5
by: Schoo | last post by:
I have some program constants that I need to set and I thought it would be best to set them all up in a central location so that I can change them quickly when we go from development to production....
5
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
2
by: Ethan V | last post by:
I have about 50 string constants that I put all of them in one file. I find that it's too un-organized because I have to intellisense thru lots of unrelated constant to get to the one I want. Is...
9
by: Jacek Dziedzic | last post by:
Hi! I often find that my programs need to store information on "current mode of something" with two or at most several mutually exclusive "modes" to choose from, e.g. - datafile: is it in a)...
4
by: Smithers | last post by:
I understand there is no "right" or "wrong" answer to the question posited below. But I'd appreciate some feedback on the "best practice" considerations - if there are any. So here goes: Are...
5
by: =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post by:
Hi, I would like to have someone comments on what's the best practice defining error codes in C. Here's what I think: solution A: using enum pros: type safe. better for debug (some debugger...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.