Hello Newsgroup,
I have an enum as such,
public enum VariablePositionEnum
{
Row = 1,
Column = 2,
RowAndColumn = 3,
}
I need (for all intensive purposes) for a control these enumeration values
as strings rather than the enum value name, i.e.
If I want the Row value as a string I need "1" not "Row". I've tried;
VariablePositionEnum.Row.ToString(); yields "Row" - Don't want this, I need
"1".
(string) VariablePositionEnum.Row; - Can't do this.
(string) (int) VariablePositionEnum.Row; - Can't do this either.
Can anyone give me a way to do so, and I hope and am sorry if this is
obviously hitting me in the face...
Many thanks and kind regards,
SpotNet. 4 1196
you can write a new class such as CVariablePositionEnum to deal it
"SpotNet" wrote: Hello Newsgroup,
I have an enum as such,
public enum VariablePositionEnum { Row = 1, Column = 2, RowAndColumn = 3, }
I need (for all intensive purposes) for a control these enumeration values as strings rather than the enum value name, i.e. If I want the Row value as a string I need "1" not "Row". I've tried;
VariablePositionEnum.Row.ToString(); yields "Row" - Don't want this, I need "1". (string) VariablePositionEnum.Row; - Can't do this. (string) (int) VariablePositionEnum.Row; - Can't do this either.
Can anyone give me a way to do so, and I hope and am sorry if this is obviously hitting me in the face...
Many thanks and kind regards, SpotNet.
SpotNet,
Have you tried one of the overloaded ToString methods?
Specifically the one that takes a format?
Something like:
string s = VariablePositionEnum.Row.ToString("D");
For details see: http://msdn.microsoft.com/library/de...matstrings.asp
Hope this helps
Jay
"SpotNet" <Sp*****@msnews.grp> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl... Hello Newsgroup,
I have an enum as such,
public enum VariablePositionEnum { Row = 1, Column = 2, RowAndColumn = 3, }
I need (for all intensive purposes) for a control these enumeration values as strings rather than the enum value name, i.e. If I want the Row value as a string I need "1" not "Row". I've tried;
VariablePositionEnum.Row.ToString(); yields "Row" - Don't want this, I need "1". (string) VariablePositionEnum.Row; - Can't do this. (string) (int) VariablePositionEnum.Row; - Can't do this either.
Can anyone give me a way to do so, and I hope and am sorry if this is obviously hitting me in the face...
Many thanks and kind regards, SpotNet.
This should get you what you want.
string enumStringValue = ((int)VariablePositionEnum.Row).ToString();
Have A Better One!
John M Deal, MCP
Necessity Software
SpotNet wrote: Hello Newsgroup,
I have an enum as such,
public enum VariablePositionEnum { Row = 1, Column = 2, RowAndColumn = 3, }
I need (for all intensive purposes) for a control these enumeration values as strings rather than the enum value name, i.e. If I want the Row value as a string I need "1" not "Row". I've tried;
VariablePositionEnum.Row.ToString(); yields "Row" - Don't want this, I need "1". (string) VariablePositionEnum.Row; - Can't do this. (string) (int) VariablePositionEnum.Row; - Can't do this either.
Can anyone give me a way to do so, and I hope and am sorry if this is obviously hitting me in the face...
Many thanks and kind regards, SpotNet.
fishbone, Jay and John,
Thanks guys, three solutions all three worked, thanks again.
Regards,
SpotNet.
"SpotNet" <Sp*****@msnews.grp> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
:
: Hello Newsgroup,
:
: I have an enum as such,
:
: public enum VariablePositionEnum
: {
: Row = 1,
: Column = 2,
: RowAndColumn = 3,
: }
:
: I need (for all intensive purposes) for a control these enumeration values
: as strings rather than the enum value name, i.e.
: If I want the Row value as a string I need "1" not "Row". I've tried;
:
: VariablePositionEnum.Row.ToString(); yields "Row" - Don't want this, I
need
: "1".
: (string) VariablePositionEnum.Row; - Can't do this.
: (string) (int) VariablePositionEnum.Row; - Can't do this either.
:
: Can anyone give me a way to do so, and I hope and am sorry if this is
: obviously hitting me in the face...
:
: Many thanks and kind regards,
: SpotNet.
:
:
:
:
: This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nebula |
last post by:
Consider
enum Side {Back,Front,Top,Bottom};
enum Side a;
Now, why is
a = 124;
legal (well it really is an integer, but still,
checking could be performed..) ?
Wouldn't enums be more useful if...
|
by: Stuart |
last post by:
I am a bit of a newbie to C# and would like help with the following
I am bringing in a dataset and transforming that dataset using an XSL style sheet to generate text. This text does in fact...
|
by: Michael C |
last post by:
If a class inherits from another class, say Form inherits from control, then
I can assign the Form to a variable of type Control without needing an
explicit conversion, eg
Form1 f = new Form1();...
|
by: Jason Larion |
last post by:
When working with enums, I've noticed some behaviour that seems
completely counter-intuitive to me. I was wondering if someone here
could help restore my sanity, or at least help me to understand...
|
by: Fred Zwarts |
last post by:
What is the recommended way to loop over all enum values of a certain enum type?
Consider the following definition:
typdef enum {A=2, B, C=5, D} E;
then
for (E x = A; x <= D; ++x) { ... }
|
by: Edward Clements |
last post by:
This post is a followup to the thread "retrieving the XmlEnumAttribute values
for an Enum" in this same forum earlier this month, since my last query in
that thread went unanswered.
I have an...
|
by: daz_oldham |
last post by:
Hi all
Starting to plod along at a steady pace now, and I think I have most of
the information that I need to be able to make a decent stab at the
project, but I have a question regarding...
|
by: tony |
last post by:
Hello!
I have below a for loop and a switch in the for loop.
I have also a enum called colBlowStep with some values.
I have also an array called m_columnBlowStep with some strings.
All items in...
|
by: surapong |
last post by:
Is there any easy way to extract the string from enum variable??
e.g. I have
enum TheEnum {ONE, TWO, THREE};
I would like to generate the array of string containing
{"ONE", "TWO", "THREE"}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
| |