Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Visual Studio target earlier C# syntax in addition to earlier .NET framework versions?

The easy part:

Targeting the .NET 2.0 framework in a Visual Studio 2010 project using the dropdown.

The hard part:

Is it possible to target a specific syntax version - for example var s = "hello world" is valid syntactic sugar in VS2008 and above, but would not compile in VS2005. Can VS2010 be configured to flag this at compile time?

like image 301
David Avatar asked Feb 14 '11 16:02

David


1 Answers

This can be done by specifying the language version in the project settings. To set the language version to C# 2.0 do the following

  • Right Click on the project and select "Properties"
  • Go to the "Build" Tab
  • Click the "Advanced" Button
  • Change the "Language Version" drop down to "ISO-2"

enter image description here

Here are the other selections and their meanings in Visual Studio 2010.

  • ISO-1: C# 1.0 / Visual Studio RTM and 2003
  • ISO-2: C# 2.0 / Visual Studio 2005
  • C# 3.0: C# 3.0 / Visual Studio 2008
  • default: C# 4.0 / Visual Studio 2010
like image 117
JaredPar Avatar answered Sep 28 '22 09:09

JaredPar