- Home /
Return Switch combined statment causing errors
I have wrote a function the works in visual studio getting no errors but when I put the script into unity it came up with 29 errors which if I make the changes it just breaks things for visual studio.
public static double EnumMath(double num0, Symbol sym, double num1)
{
return sym switch
{
(Symbol.Plus) => num0 + num1,
(Symbol.Minus) => num0 - num1,
(Symbol.Multipy) => num0 * num1,
(Symbol.Divide) => num0 / num1,
_ => 0,
};
}
I know multiple different ways I could rewrite this function but was wondering why Unity doesn't like it and if there are any ways to get it to work in unity
Answer by gjf · Jun 12, 2020 at 12:02 PM
That's C# 8 code, which isn't currently compatible with Unity.
Refer to this thread: https://forum.unity.com/threads/unity-c-8-support.663757/
Okay makes sense. I try to be careful of that in the future
Your answer
Follow this Question
Related Questions
JavaScript switch returns warn for unreachable code. 1 Answer
How to return from the last case to the first 1 Answer
GUI Script switching on and off. 1 Answer
Switch Statement question 0 Answers
Camera switching trouble 2 Answers