M
ME
In C# the following code generates a compiler error
("A constant value is expected"):
public void Test(string value)
{
switch (value)
{
case SimpleEnum.One.ToString():
MessageBox.Show("Test 1");
break;
case SimpleEnum.Two.ToString():
MessageBox.Show("Test 2");
break;
case SimpleEnum.Three.ToString():
MessageBox.Show("Test 3");
break;
}
}
The Visual Basic.NET version does not:
Public Sub Test(ByVal value As String)
Select Case value
Case SimpleEnum.One.ToString()
MessageBox.Show("Test 1")
Case SimpleEnum.Two.ToString()
MessageBox.Show("Test 2")
Case SimpleEnum.Three.ToString()
MessageBox.Show("Test 3")
Case Else
End Select
End Sub
How can this be done in C#?
Thanks,
Matt
("A constant value is expected"):
public void Test(string value)
{
switch (value)
{
case SimpleEnum.One.ToString():
MessageBox.Show("Test 1");
break;
case SimpleEnum.Two.ToString():
MessageBox.Show("Test 2");
break;
case SimpleEnum.Three.ToString():
MessageBox.Show("Test 3");
break;
}
}
The Visual Basic.NET version does not:
Public Sub Test(ByVal value As String)
Select Case value
Case SimpleEnum.One.ToString()
MessageBox.Show("Test 1")
Case SimpleEnum.Two.ToString()
MessageBox.Show("Test 2")
Case SimpleEnum.Three.ToString()
MessageBox.Show("Test 3")
Case Else
End Select
End Sub
How can this be done in C#?
Thanks,
Matt