473,400 Members | 2,145 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,400 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 3953
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.