As others have said, C # 3.0 features can be used when setting up the .NET 2.0 runtime using the C # 3.0 compiler.
A slightly known fact related to this is that you can even use LINQ with .NET 2.0 if you provide your own implementation of LINQ.
Here is an example that allows operators to "select" and "where":
namespace System.Runtime.CompilerServices { // defining this attribute allows using extension methods with .NET 2.0 [AttributeUsage(AttributeTargets.Method)] public sealed class ExtensionAttribute : Attribute {} } namespace System { public delegate R Func<A, R>(A arg0); } namespace System.Linq { public static class Enumerable { public static IEnumerable<R> Select<T, R>(this IEnumerable<T> input, Func<T, R> f) { foreach (T element in input) yield return f(element); } public static IEnumerable<T> Where<T>(this IEnumerable<T> input, Func<T, bool> f) { foreach (T element in input) { if (f(element)) yield return element; } } }
You can send the Mono version of System.Core with your application if you want to make full use of LINQ on .NET 2.0.
source share