0

I've inherited an app. The app has to use .NET 2.0. However, I would like to make use of a feature introduce in C# 4.0 (optional arguments). I understand that a framework is separate from a language. However, what I'm not sure of is, can I use this C# feature in the context of .NET 2.0?

The code compiles. I wasn't sure if this was legitimate, or if I just got lucky :).

Thank you for your insights.

2
  • How are you connecting the frameworks? The app is 2.0 and you have a class library in 4.0? Commented Jul 22, 2014 at 17:50
  • 3
    The C# compiler doesn't care that much that you use an ancient .NET version. Unless you use a feature that requires framework support, like dynamic or Linq. Optional arguments don't need any. Commented Jul 22, 2014 at 17:51

1 Answer 1

2

Optional arguments/parameters have been supported in CLR since CLR 1.0. This is due to CLR support for VB.net.

This is why your code compiles. Other new 4.0 features may not work the same.

Other post-C# 2.0 features that will compile into a .NET 2.0 application include named arguments, lambda expressions, auto properties, & extension methods.

Sign up to request clarification or add additional context in comments.

2 Comments

LINQ also compiles (it's syntactic sugar for .Select(), .Where() and so on). Although if you want to use LINQ to Objects you will not have the required extension methods in .net 2. But you can reference libraries to fill the gap, namely LinqBridge.
And by the way: it's possible to compile extension methods, but they also need that your project includes an attribute that is missing in .net 2: System.Runtime.CompilerServices.ExtensionAttribute.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.