Today one of my junior asked me what C# version we are working? To my surprise most of my colleagues had no idea about it and almost none of them knew what is default version of visual studio editor or how to change the default version of C# in visual studio editor. I demonstrated them how to change the default c# version of visual studio and also explained different C# versions in different visual studio editors.
In this blog I will try to explain different version of C# with .net framework and visual studio editor.
These are the versions of C# known about at the time of this writing:
- C# 1.0 released with .NET 1.0 and VS2002 (January 2002)
- C# 1.2 (bizarrely enough); released with .NET 1.1 and VS2003 (April 2003). First version to call Dispose on IEnumerators which implemented IDisposable. A few other small features.
- C# 2.0 released with .NET 2.0 and VS2005 (November 2005). Major new features: generics, anonymous methods, nullable types, iterator blocks
- C# 3.0 released with .NET 3.5 and VS2008 (November 2007). Major new features: lambda expressions, extension methods, expression trees, anonymous types, implicit typing (var), query expressions
- C# 4.0 released with .NET 4 and VS2010 (April 2010). Major new features: late binding (dynamic), delegate and interface generic variance, more COM support, named arguments, tuple data type and optional parameters
- C# 5.0 released with .NET 4.5 and VS2012 (August 2012). Major features: async programming, caller info attributes. Breaking change: loop variable closure.
- C# 6.0 released with .NET 4.6 and VS2015 (July 2015). Implemented by Roslyn. Features: initializers for automatically implemented properties, using directives to import static members, exception filters, indexed members and element initializers, await in catch and finally, extension Add methods in collection initializers.
- C# 7.0 released with VS2017 (March 2017) Major new features: tuples, ref locals and ref return, pattern matching (including pattern-based switch statements), inline out parameter declarations, local functions, binary literals, digit separators, and arbitrary async returns.
More detailed information about the relationship between the language, runtime and framework versions is available on the C# in Depth site. This includes information about which features of C# 3.0 you can use when targeting .NET 2.0.
The biggest problem when dealing with C#’s version numbers is the fact that it is not tied to a version of the .NET Framework, which it appears to be due to the synchronized releases between Visual Studio and the .NET Framework. The version of C# is actually bound to the compiler, not the framework. For instance, in VS2008 you can write C# 3.0 and target .NET Framework 2.0, 3.0 and 3.5.
How to change default C# version in visual studio editor?
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)
- Modify Project Properties as per below steps:
- Select “Build” from left hand side options
- 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”
As of May 3, 2017, the C# Language Team created a history of C# versions and features on their github repo: Features Added in C# Language Versions
I hope this tip will this will help someone’s and save their time and effort.