We can enum to represent a interger using a string. But how can we use enum
to represent string
below is what I want to achieve.
Public Enum country
Netherlands = "nl"
America = "US"
France = "fr"
End Enum
Obviously above code does not work. How can I achieve a similiar function
like above???
regards,
Guoqi Zheng http://www.ureader.com 2 1694
guoqi zheng wrote: We can enum to represent a interger using a string. But how can we use enum to represent string
below is what I want to achieve.
Public Enum country Netherlands = "nl" America = "US" France = "fr" End Enum
Obviously above code does not work. How can I achieve a similiar function like above???
regards,
Guoqi Zheng http://www.ureader.com
What you can try to simulate this:
use a class ("country"), that contains (only) a set of string constants.
In C#:
public class Country
{
public const string Netherlands = "nl";
public const string America = "us";
public const string France = "fr";
}
Hans Kesting
}
It's not quite as readable as the actual country name, but you could also do
this:
Public Enum Country
nl,
US,
fr
End Enum
....if you need the string value, you can then do, for example,
Country.nl.ToString().
The advantage over using a Class is that it's strongly typed.
The disadvantage is that you need to know the country code rather than the
name when you develop.
HTH,
R.
"guoqi zheng" wrote: We can enum to represent a interger using a string. But how can we use enum to represent string
below is what I want to achieve.
Public Enum country Netherlands = "nl" America = "US" France = "fr" End Enum
Obviously above code does not work. How can I achieve a similiar function like above???
regards,
Guoqi Zheng http://www.ureader.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: AngleWyrm |
last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T,
section 4.8 (pp 77):
"A value of integral type may be explicitly converted to an enumeration
type. The result of such a...
|
by: Ben |
last post by:
Hi all,
enum Colors defined as:
enum Colors{Red, Blue, Green};
I have a text file "colors.txt" with the following content, one per
line:
Red
Blue
Green.
|
by: Dennis Schulz |
last post by:
Hi this is my problem:
enum num{Jan=1, Feb=2, Mar=3, Apr=4, May=5, Jun=6, Jul=7, Aug=8,
Sep=9, Okt=10, Nov=11, Dec=12};
std::string month = "Dec";
num n1 = Dec; //this is working
num n2...
|
by: James Brown |
last post by:
Hi,
I have the following enum declared:
enum TOKEN { TOK_ID = 1000, TOK_NUMBER, TOK_STRING, /*lots more here*/ };
What I am trying to do is _also_ represent ASCII values 0-127 as TOKENs...
|
by: Nikhil Patel |
last post by:
Hi all,
I am a VB6 programmer and learning C#. I am currently reading a chapter
on types. I have question regarding enums. Why do we need to convert enum
members to the value that they represent?...
|
by: Popoxinhxan |
last post by:
Hi guy, i just wondering that is it posible to convert the array of string to
enum types dynamically, for example i get the list of countries name from
database and would like to convert all of...
|
by: Simon Elliott |
last post by:
What operators can be used to extend an enum?
Can I extend an enum with an operator= and if so what's the syntax?
--
Simon Elliott http://www.ctsn.co.uk
|
by: jonpb |
last post by:
The documentation for the "is" keyword says:
An is expression evaluates to true if the provided expression is
non-null, and the provided object can be cast to the provided type
without causing...
|
by: Chevron Boyde |
last post by:
Hi There
I have some codes that represent Sale Types i.e. A = On Account, C = Cash, D
= Debtor, V = Voucher
I want to create an enum or struct to work with the logical names like
"Cash" as...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |