T
tony
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 go
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; column++)
{
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
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 go
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; column++)
{
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