Does unity support the C# keyword var and if not are there plans to support it?
I did some research and found that mono seems to support three versions of C#: 1, 2 and 3. In 2007, they added support to C# 3 for the var keyword. I'm not sure what version of mono is being used in Unity and if it should support var (maybe I'm doing something wrong).
As @The Stone and @Ricardo were nice enough to point out, Unity is currently supporting an older version of mono that doesn't yet support the C# 3 feature set (var, LINQ, etc). They are investigating it and would have implemented it with Unity 2.6, but it would break backwards compatibility.
Currently there is a lot of interesting discussion in the user voice page for it so feel free to read about it/vote it up if it is important to you.
Hey all, with the Unity 3.0 announcement and a pending release in Summer 2010 it looks like this feature will be implemented. I can't wait.
Unity does not use the latest version of mono. The latest version is 2.4 and 2.6 will be out soon, right now Unity uses an 1x version, they haven't upgraded due to doing so will break all existing web player games. But I guess they will do so when Unity 3.0 comes, I hope so at least.
answered Nov 25 '09 at 07:39 AM
Here's a trick I am using to get C# 3.0 language support for var, extension methods, lambda expressions, object initializers, collection initializers, implicitly typed arrays, expression trees, auto implemented properties, and query expressions.
I've only done this for Windows. The Mac instructions are probably analogous.
Download and install the latest version of Mono (2.6.1)
Copy these files: gmcs.exe, gmcs.exe.config
From: C:\Program Files\Mono-2.6.1\lib\mono\2.0
This only works because C# 3.0 compiles into IL compatible with the 2.0 runtime. Though, linq to objects does require a change to System.Core (which came with .NET Framework 2.0 SP1)... but linq code compiles and runs fine for me, so I guess the version of mono that Unity is using includes this change. What definitely doesn't work is linq to sql, because that requires System.Data.Linq
Your guess is correct TheLameDuck - Unity is still only up to C# 2.0. That means no var declaration, no nice collection initializers, and no Linq.
answered Nov 25 '09 at 02:29 PM
We managed to replace only the gmcs.exe (without replacing any other file) And almost all 3.0 languages constructs became supported.
Since it's a compile time only change it seens pretty safe. We tested this change with a project with hundreds of c# classes
We used unity 2.6.1f1 and gmcs.exe 2.0.50727.143
answered Jan 13 '10 at 11:47 AM
Daniel Sperry 2