R
ryanm
I have this function:
private void ParseCommands(String cmd){
switch(cmd)
{
case "!rpt":
Report();
break;
// other cases removed for brevity
default:
Console.WriteLine(cmd);
break;
}
}
...as a member of a class. The class wants to pass a string that may be
text for display, or it may be a command being issued. The problem is that
even if the value being passed to the function is "!rpt", the "!rpt" case
never executes, it always goes to default. Now, the docs say that == is a
value comparison for strings (rather than a reference comparison), and that
the switch expression is evaluated as == to the case value, but it never
returns true. Am I doing something obvious wrong and I just don't see it, or
do I have to do it another way? I tried comparing the values with Compare
and CompareTo, but neither ever returned 0 (equal) for me.
What am I missing?
ryanm
private void ParseCommands(String cmd){
switch(cmd)
{
case "!rpt":
Report();
break;
// other cases removed for brevity
default:
Console.WriteLine(cmd);
break;
}
}
...as a member of a class. The class wants to pass a string that may be
text for display, or it may be a command being issued. The problem is that
even if the value being passed to the function is "!rpt", the "!rpt" case
never executes, it always goes to default. Now, the docs say that == is a
value comparison for strings (rather than a reference comparison), and that
the switch expression is evaluated as == to the case value, but it never
returns true. Am I doing something obvious wrong and I just don't see it, or
do I have to do it another way? I tried comparing the values with Compare
and CompareTo, but neither ever returned 0 (equal) for me.
What am I missing?
ryanm