# Kat's UdonSharp Handbook

This is my attempt at documenting niche UdonSharp related quirks.

# Switch statements

U# compiles switch statements to a jump table if the following conditions are met:

1. The input evaluates to an integer type
2. The switch has **at least 4** and no more than ***257*** cases
3. The case values are in the range **0 - 256** (inclusive)

This means that you can have at most **257** value cases and a `default` case.  
The cases can be declared in any order**.**

<p class="callout info">Enums only exist at compile-time in U#. They are Int32 at runtime since the Udon VM has no support for enums.</p>

### Examples

Switch statement that compiles to a jump table:

```c#
switch (inputValue)
{
    case 256:
        Debug.Log("256");
        break;
    case 0:
        Debug.Log("0");
        break;
    case 2:
        Debug.Log("2");
        break;
    case 123:
        Debug.Log("123");
        break;
    default:
        Debug.Log("Default value");
        break;
}

```

Switch statement that **does not** compile to a jump table and instead becomes `if else if else if else ...`

```c#
switch (inputValue)
{
    case -1:
        Debug.Log("-1");
        break;
    case 257:
        Debug.Log("257");
        break;
    default:
        Debug.Log("Default value");
        break;
}

```