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:
- Right click on the Project Name
- Select "Properties" (last option in menu)
Above steps are shown below with reference numbering:
- Modify Project Properties as per below steps:
- Select "Build" from left hand side options
- Scroll down till end and click on "Advance" button.
- It will open a popup and there you will get "Language Version" dropdown
- Select desired version of C# and Click "OK"
Above steps are shown below with reference numbering:
Default versions of C#
By default following are corresponding version of C# compilers for Visual Studio:
- Visual Studio 2015: C# 6.0
- Visual Studio 2013: C# 5.0
- Visual Studio 2012: C# 5.0
- Visual Studio 2010: C# 4.0
- Visual Studio 2008: C# 3.0
- Visual Studio 2005: C# 2.0
- Visual Studio.NET 2003: C# 1.2
- 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