C# - Doesn't Unity support Expression Bodied Properties?

I have this line of code in C#.

private static float Width => 0.015f;

Unity is complaining about the following:

Unexpected symbol `=>' in class, struct, or interface member declaration

Doesn’t Unity support Expression Bodied Properties?

It’s a new amazing feature of C# 6.0

You can now change framework: (Project Settings > Player > Other Settings)
105333-skjermbilde.png

@israelg99 I feel your pain. Sadly, there’s not a lot you can do about it unless you can write a lot of your code on a seperate library outside of Unity.

Many of the new C# 6.0 features can be used with .NET 3.5 framework target code because they’re just syntactic sugar that lets you type less. The compiled CLR (Common Language Runtime) bytecode is identical. Alas, Roslyn (which is what Microsoft named their new C# 6.0 compiler) is only currently being used in Visual Studio. The .NET Framework version (2.0, 3.5, 4.0 etc) and the C# version aren’t the same thing.

If you write your code as a seperately compiled DLL and use Visual Studio you can use expression bodies and all the other C# 6.0 features (those supported in the .NET 3.5 target at least) with Unity because it’s all compiled to valid .NET 3.5 Framework bytecode inside the DLL and Unity won’t complain. However, Unity’s built in automatic compiler is old and won’t understand the newer syntax. I hope they update it , Microsoft already have Roslyn running on a Mac with Visual Sdutio Code.

I think the only .NET 3.5 features that unity doesn’t support are largly based around IL injection, code emit and dynamic compilation (Expression classes etc).

no, it doesn’t. not sure what the latest version of c# used is (check the docs), but it’s definitely not 6.0.

@Cameron860 @Bunny82
I have this line of code:


public static float4x4 identity => new float4x4
{
m0 = new float4(1.0f, 0.0f, 0.0f, 0.0f),
m1 = new float4(0.0f, 1.0f, 0.0f, 0.0f),
m2 = new float4(0.0f, 0.0f, 1.0f, 0.0f),
m3 = new float4(0.0f, 0.0f, 0.0f, 1.0f)
};


For what I should to change this?

My error is "Feature `expression bodied members’ cannot be used because it is not part of the C# 4.0 language specification´

Thanks!