Hey!
I’ve read that from Unity 2020.2 onwards some c#8 features like switch expressions are available in Unity.
I have this simple code piece that works for me in Unity 2020.2.1f:
public State GetState(StateType stateType)
{
return stateType switch
{
StateType.Idle => Idle,
StateType.Move => Move,
StateType.Fall => Fall,
StateType.Climbing => Climbing,
StateType.Jump => Jump,
StateType.Attack => Attack,
_ => throw new System.Exception("State not defined " + stateType.ToString()),
};
}
A friend with unity 2020.3.3f1 tried to type it and received an error:
His Visual Studio IDE doesn’t even show a quick help option to convert a default switch statement to switch expression which works perfectly fine in my project:
Can there be any specific reason for this behaviour? Can outdated IDE cause the issue? I would assume that it isn’t caused by mistakenly creating a project in an older Unity version.
Thanks!
PS.
Project is indeed in 2020.3.3f1 so theoretically switch expressions should work there by default.