65.9K
CodeProject is changing. Read more.
Home

How to change targeted C# version in Visual Studio

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.94/5 (37 votes)

Jan 14, 2015

CPOL

2 min read

viewsIcon

297331

I found that changing targeted C# version for a project in Visual Studio is bit tricky. And even if you choose old .NET framework version, Visual studio will use default C# version to compile C# code, until you explicitly set the targeted C# version.

Introduction

I was doing some experiment with C# 6 using Visual Studio 2015 Preview. I created two projects and for one project I wanted to target C# 6 which is default in Visual Studio 2015 so no effort is needed in this case. But for other project I wanted to write code doing same thing but targeting C# 5, in order to compare and appreciate how better it is now in C# 6. I found that to set targeted C# version is not straightforward in Visual Studio. It is very simple but tricky so I will share that trick here.

Changing targeted C# Version

To target desired version of language for a project in Visual Studio, we need to take following steps:

  • Open the project properties window:
    1. Right click on the Project Name
    2. Select "Properties" (last option in menu)
    Above steps are shown below with reference numbering:

    Project Propeties


  • Modify Project Properties as per below steps:
    1. Select "Build" from left hand side options
    2. Scroll down till end and click on "Advance" button.
    3. It will open a popup and there you will get "Language Version" dropdown
    4. Select desired version of C# and Click "OK"
    Above steps are shown below with reference numbering:

    Provide Value for Parameter

Default versions of C#

By default following are corresponding version of C# compilers for Visual Studio:

  1. Visual Studio 2015: C# 6.0
  2. Visual Studio 2013: C# 5.0
  3. Visual Studio 2012: C# 5.0
  4. Visual Studio 2010: C# 4.0
  5. Visual Studio 2008: C# 3.0
  6. Visual Studio 2005: C# 2.0
  7. Visual Studio.NET 2003: C# 1.2
  8. Visual Studio.NET 2002: C# 1.0

Conclusion

Hope this tip may help and save time for beginners to Visual Studio and trying to change targeted C# Version. Your comments and suggestions are most welcome to make this article more useful. Thanks.

Reference

C# - Wikipedia Page