Use List.Average() in MonoDevelop


Why isn’t the function System.Collections.Generic.List.Average() present when working in Unity3D?

When I copy the code below into Visual Studio C# it all compiles find but in MonoDevelop I get a compiler error saying that there is no function called Average():

// The following is valid code in Visual Studio C# but not in MonoDevelop??
System.Collections.Generic.List<double> a = new System.Collections.Generic.List<double>();
double average = a.Average();

Whats going wrong? Am I including an older/wrong version of .NET?

I believe that’s a LINQ extension method.

You probably need to do a:

using System.Linq;

The answer is quite simple, unity doesn’t use .Net.

Unity uses mono (2.6 as far as I remember which mostly equals .Net 3.0 and also have some .Net 3.5 functions / classes).

In general if you want to know what’s available, see this page: