I am converting some VB.NET code to C#, as I am more comfortable with it and it helps me in resolving issues faster. However, I came across this code which is NOT an error in VB.NET — but converting it to C# is generating a compiler error.
VB.NET Code
Select Case name
Case "FSTF"
.....
Case "FSTF"
.....
End Select
C# Converted Code
switch(name) {
case "FSTF":
....;
break;
case "FSTF":
....;
break;
}
And the error is:
The Label ‘case “FSTF”:’ already occurs in this switch statement.
What is the solution here — does it mean that in the VB.NET code, the second case statement was just a dummy — or was the first case a dummy?
From the documentation for Select…Case:
So here the second case is effectively redundant. Personally I prefer the C# approach of highlighting what was almost certainly an unnoticed programming error rather than the deliberate introduction of a duplicate case…