What are the correct version numbers for C#?


What are the correct version numbers for C#? What came out when? Why can't I find any answers about C# 3.5?

This question is primarily to aid those who are searching for an answer using an incorrect version number, e.g. "C# 3.5". The hope is that anyone failing to find an answer with the wrong version number will find this question and then search again with the right version number.



Answers


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 .NET 4.7 and 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.
  • C# 7.1 released with .NET 4.7 and VS2017 v15.3 (August 2017) Minor new features: async main, tuple member name inference, default expression, pattern matching with generics.

There is no such thing as C# 3.5 - the cause of confusion here is that the C# 3.0 is present in .NET 3.5. The language and framework are versioned independently, however - as is the CLR, which is at version 2.0 for .NET 2.0 through 3.5, .NET 4 introducing CLR 4.0, service packs notwithstanding. The CLR in .NET 4.5 has various improvements, but the versioning is unclear: in some places it may be referred to as CLR 4.5 (this MSDN page used to refer to it that way, for example), but the Environment.Version property still reports 4.0.xxx.

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. (If anyone wants to bring all of the content into this wiki answer, they're welcome to.)

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




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 Visual Studio 2008 you can write C# 3.0 and target .NET Framework 2.0, 3.0 and 3.5. The C# 3.0 nomenclature describes the version of the code syntax and supported features in the same way that ANSI C89, C90, C99 describe the code syntax/features for C.

Take a look at Mono, and you will see that Mono 2.0 (mostly implemented version 2.0 of the .NET Framework from the ECMA specifications) supports the C# 3.0 syntax and features.




  • C# 1.0 with Visual Studio.NET

  • C# 2.0 with Visual Studio 2005

  • C# 3.0 with Visual Studio 2008

  • C# 4.0 with Visual Studio 2010

  • C# 5.0 with Visual Studio 2012

  • C# 6.0 with Visual Studio 2015

  • C# 7.0 with Visual Studio 2017




C# Version and .NET Framework Version?

I am not sure what your actual question is, but if it is what are the current versions..

C#: 3.0
.NET Framework: 3.5

You might also want to take a look at this breakdown chart. It provides the Framework, language and CLR relations.




C# 1.0 - Managed Code

C# 2.0 - Generics, Nullable Types, Anonymous Delegates, Partial Classes / Methods

C# 3.0 - LINQ, Lambda Expressions, Implicit Variable Typing, Streamlined Object Initialization

// Related? somewhat perhaps




.net 2 C# 2

.net 3 C# 2

.net 3.5 C# 3




What is the difference between C# versions like ver 2.0 and ver 3.0?

Many new features support the introduction of LINQ (they can be used in many different contexts, but they are very useful in the context of LINQ).

I strongly suggest you read Jon Skeet's C# in Depth for a detailed explanation of each new feature.




From Jon Skeet's book C# in Depth, the web page is here for detail.

C# 2, introducing generics, nullable types, anonymous methods, iterator blocks and some other more minor features

C# 3, introducing implicit typing, object and collection initializers, anonymous types, automatic properties, lambda expressions, extension methods, query expressions and some other minor features







Proper way to initialize a C# dictionary with values already in it?

I can't reproduce this issue in a simple .NET 4.0 console application:

static class Program
{
    static void Main(string[] args)
    {
        Dictionary<string, string> myDict = new Dictionary<string, string>
        {
            { "key1", "value1" },
            { "key2", "value2" }
        };

        Console.ReadKey();
    }
}

Can you try to reproduce it in a simple Console application and go from there? It seems likely that you're targeting .NET 2.0 (which doesn't support it) or client profile framework, rather than a version of .NET that supports initialization syntax.




With C# 6.0, you can create a dictionary in following way:

var dict=new Dictionary<string,int>
         {
            ["one"]=1,
            ["two"]=2,
            ["three"]=3
         };

It even works with custom types.




You can initialize a Dictionary (and other Collections) inline. Each member is contained with braces:

Dictionary<int, StudentName> students = new Dictionary<int, StudentName>()
{
    { 111, new StudentName {FirstName="Sachin", LastName="Karnik", ID=211}},
    { 112, new StudentName {FirstName="Dina", LastName="Salimzianova", ID=317}},
    { 113, new StudentName {FirstName="Andy", LastName="Ruth", ID=198}}
};

See MSDN for details (https://msdn.microsoft.com/en-us/library/bb531208.aspx)