Click here to Skip to main content
15,886,806 members
Articles / Programming Languages / C#
Tip/Trick

How to change targeted C# version in Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.94/5 (37 votes)
14 Jan 2015CPOL2 min read 291.9K   17   18
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
I am a Software Developer working on Microsoft technologies. My interest is exploring and sharing the awesomeness of emerging technologies.

Comments and Discussions

 
QuestionC# version Pin
Member 1379567924-Apr-18 2:20
Member 1379567924-Apr-18 2:20 
AnswerRe: C# version Pin
OriginalGriff24-Apr-18 2:23
mveOriginalGriff24-Apr-18 2:23 
QuestionVS 2015 Community Pin
Edward_7530-Mar-17 6:40
Edward_7530-Mar-17 6:40 
GeneralMy vote of 5 Pin
Member 1182599831-Aug-15 6:17
Member 1182599831-Aug-15 6:17 
GeneralRe: My vote of 5 Pin
Snesh Prajapati31-Aug-15 15:43
professionalSnesh Prajapati31-Aug-15 15:43 
QuestionIs there a way to change the default? Pin
priteshacharya20-Aug-15 6:33
priteshacharya20-Aug-15 6:33 
AnswerRe: Is there a way to change the default? Pin
Snesh Prajapati20-Aug-15 7:19
professionalSnesh Prajapati20-Aug-15 7:19 
SuggestionIt's a tip! Pin
_Dhull 4-Aug-15 20:23
_Dhull 4-Aug-15 20:23 
GeneralMy vote of 5 Pin
rosdi18-May-15 7:25
rosdi18-May-15 7:25 
AnswerRe: My vote of 5 Pin
Snesh Prajapati18-May-15 15:55
professionalSnesh Prajapati18-May-15 15:55 
QuestionInteresting - my results vary Pin
B. Clay Shannon19-Jan-15 10:37
professionalB. Clay Shannon19-Jan-15 10:37 
AnswerRe: Interesting - my results vary Pin
Snesh Prajapati19-Jan-15 17:00
professionalSnesh Prajapati19-Jan-15 17:00 
QuestionWhy? Pin
Gorpik15-Jan-15 2:00
Gorpik15-Jan-15 2:00 
AnswerRe: Why? Pin
PeterLudvik15-Jan-15 2:24
professionalPeterLudvik15-Jan-15 2:24 
For professional developers supplying code for third parties (i.e. their clients) to maintain this is quite essential.

Most large corporate clients DO NOT upgrade to the latest versions of .NET or development tools as soon as they appear.

I have been asked recently to develop some software and specifically to target .NET 3.5 and C# 4 (VS 2010) as that is still their default production environment.

So to be able to produce software using 'obsolete' environments is actually very useful!
GeneralRe: Why? Pin
Gorpik15-Jan-15 4:26
Gorpik15-Jan-15 4:26 
GeneralRe: Why? Another Reason Pin
ozbear15-Jan-15 10:54
ozbear15-Jan-15 10:54 
GeneralMy vote of 5 Pin
Sid_Joshi14-Jan-15 19:09
professionalSid_Joshi14-Jan-15 19:09 
GeneralRe: My vote of 5 Pin
Snesh Prajapati14-Jan-15 19:12
professionalSnesh Prajapati14-Jan-15 19:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.