Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project compiled against .NET Framework 3.5 allows C# 4.0 features

I currently have a project I'm working on that has a target of .NET Framework 3.5. I am using Visual Studio 2010; however my coworkers use Visual Studio 2008. I am able to use C# 4.0 features such as optional function parameters, but if they try to build the same code with the same target, they are unable to. It was my understanding that even though I was using Visual Studio 2010 I would not be able to use .NET 4.0 features since the target was .NET 3.5.

like image 402
Kyle Avatar asked Oct 25 '10 20:10

Kyle


1 Answers

By default the multi-targeting framework only restricts the set of features that would cause compatibility issues with the CLR (not source code). Hence named and optional is legal because there is no issue using it on the 2.0 or 3.5 CLR.

If you want to restrict the set of C# features to those legal on the 3.5 compiler you need to change the language version option.

  • Right click on project and select properties
  • Go to build tab
  • Click the Advanced button
  • Switch the Language Version combo to "C# 3.0"

alt text

like image 54
JaredPar Avatar answered Oct 05 '22 23:10

JaredPar