How to Resolve Warning "CS0469: The 'goto case' value is not implicitly convertible to type 'Type'" in C#
The Compiler Warning CS0469 (often treated as an error in modern versions) is a type compatibility issue inside a switch statement. The message reads: "The 'goto case' value is not implicitly convertible to type 'Type'".
In C#, the switch statement operates on a specific governing type (e.g., int, string, enum). When you use the goto case statement to jump to another label, the value you provide must be compatible with that governing type. If the value requires an explicit conversion (cast) to match the switch type, or if the types are completely incompatible, the compiler raises this warning/error because it cannot guarantee the jump is safe or logical.
This guide explains how to align your goto case labels with your switch variables.
Understanding goto case Type Safety
When you declare switch (myVariable), the compiler expects every case label and every goto case target to match the type of myVariable.
- Implicit Conversion: Safe. (e.g.,
inttolong). - No Implicit Conversion: Unsafe. (e.g.,
longtoint, ordoubletoint).
If you try to jump to a value that is technically a different type (like a long literal 5L) inside an int switch, the compiler warns you that the value provided isn't naturally an int.
Scenario 1: Numeric Mismatches (Long vs Int)
This is a common occurrence when copy-pasting numbers or using suffixes incorrectly.
Example of error: you are switching on an int, but you tell the code to go to a long value.
public void Process(int status)
{
switch (status)
{
case 1:
System.Console.WriteLine("Start");
// ⛔️ Warning/Error CS0469: The 'goto case' value is not implicitly
// convertible to type 'int'.
// '2L' is a long (64-bit). 'status' is an int (32-bit).
// A long cannot implicitly convert to an int.
goto case 2L;
case 2:
System.Console.WriteLine("Continue");
break;
}
}
Scenario 2: Character vs Integer
C# treats char as a numeric type (16-bit integer), but it enforces strict conversion rules. While you can often assign integer literals to characters, goto case is strict about the format.
Example
Switching on a char, but trying to jump using an integer representation.
public void CheckKey(char c)
{
switch (c)
{
case 'A':
// ⛔️ Warning CS0469: 66 is an int. The switch is on 'char'.
goto case 66;
case 'B': // 'B' is ASCII 66
System.Console.WriteLine("B was selected");
break;
}
}
Solution: Match Literals or Cast
To fix this, ensure the value after goto case matches the type of the switch expression exactly.
Fix 1: Use the Correct Literal Syntax
Remove suffixes or change the format to match the type.
public void Process(int status)
{
switch (status)
{
case 1:
// ✅ Correct: '2' is an int literal. Matches 'status'.
goto case 2;
case 2:
break;
}
}
Fix 2: Explicit Cast (If necessary)
If you are working with constants defined elsewhere, use a cast.
public void CheckKey(char c)
{
switch (c)
{
case 'A':
// ✅ Correct: Explicitly convert the int 66 to a char 'B'.
goto case (char)66;
case 'B':
break;
}
}
Conclusion
CS0469 ensures that your control flow logic is typesafe.
- Check the Switch: What type is inside
switch(...)? - Check the Goto: What type is after
goto case ...? - Align Them: Remove suffixes (
L,f,d) or use casts(int)to ensure the types match exactly.