Re: Have some problem with enum and string
- From: tbain <tbain@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Sep 2006 05:46:02 -0700
Perhaps using Enum.GetValues and Enum.GetNames can be used to convert between
the the string representation of the enum verses the byte values? Not sure
this is what you need but thought I'd give this as an avenue to persue. Hope
this helps.
--
Thom
"tony" wrote:
Hello!.
This doesn't work because
m_columnBlowStep [column])
in not an int it's a string.
Any better idea?
//Tony
"Sean Chambers" <dkode8@xxxxxxxxx> skrev i meddelandet
news:1158839557.293577.312640@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Instead of trying to Convert.ToInt32, you have to parse the string andgo
tell C# that you know the string is an int value like so:
(colBlowStep)Int32.Parse(m_columnBlowStep [column])
That should work.
hope that helps!
Sean
tony wrote:
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 the array[] m_columnBlowStep is string because I have used
ToString on each enum item as you can see.
I want to use enum in the case statment in the switch.
I know I can use string but I rather want to use enum.
The problem is that I can't match string that exist in m_columnBlowStep
[column]
with enum that I have in the case statements.
I can't write in this way
switch( (colBlowStep)Convert.ToInt32( m_columnBlowStep [column] ) )
because I can't convert a string to an int.
So what I want is to loop through the for loop check the switch and then
column++)to the corresponing
case where I have enum values.
So is it possible to use string as I have with enum in the case.
private enum colBlowStep : byte
{
No, BlowSteps, EndCond, Value, Ref, N_switch
}
private string[] m_columnBlowStep = { colBlowStep.No.ToString(),
colBlowStep.BlowSteps.ToString(), colBlowStep.EndCond.ToString(),
colBlowStep.Value.ToString(), colBlowStep.Ref.ToString(),
colBlowStep.N_switch.ToString() };
for (int column = 0; column < m_flgBlowStep.Columns.Items.Count;
{
switch( (colBlowStep)Convert.ToInt32( m_columnBlowStep [column] ) )
{
case colBlowStep.No :
...
break;
case colBlowStep.BlowSteps :
...
break;
case colBlowStep.EndCond :
...
break;
case colBlowStep.Value :
...
break;
case colBlowStep.Ref :
...
break;
case colBlowStep.N_switch :
...
break;
}
}
//Tony
- References:
- Have some problem with enum and string
- From: tony
- Re: Have some problem with enum and string
- From: Sean Chambers
- Re: Have some problem with enum and string
- From: tony
- Have some problem with enum and string
- Prev by Date: Re: OSQL userName and Password Prompt.
- Next by Date: C# - Plugin Design
- Previous by thread: Re: Have some problem with enum and string
- Next by thread: Re: Have some problem with enum and string
- Index(es):
Relevant Pages
|