left-icon

C# Features Succinctly®
by Dirk Strauss

Previous
Chapter

of
A
A
A

CHAPTER 1

The History of C#

The History of C#


C# is continuing to evolve and improve with each major release of the language. As the C# team is innovating and adding features to C#, its members share their thought process around the design of C# with the community.

If you head over to the dotnet/Roslyn repository on GitHub, you will see detailed language feature statuses as well as features that the C# team is considering for upcoming releases. You can also view a history C# on the Microsoft Docs. As of this writing, of particular interest are the planned features surrounding C# 9. Later in this book, we will have a look at what is planned for C# 9.

The C# build tools will default the language version to the latest major release. As of C# 7.0, however, developers started seeing more point releases in the form of versions C# 7.1, C# 7.2, and C# 7.3.

C# language version

When creating a new project in Visual Studio, the C# compiler figures out which version of C# to use based on the target framework of your project. This ensures you do not use a language version that requires types or runtime behavior not available in the target framework of the project.

It is worth mentioning that C# 8.0 and higher will only be supported on .NET Core 3.x and later. Table 1 outlines the C# language defaults based on the target framework.

Table 1: Language version default mapping

Target framework

Version

C# language default

.NET Core

3.x

C# 8.0

.NET Core

2.x

C# 7.3

.NET Standard

2.1

C# 8.0

.NET Standard

2.0

C# 7.3

.NET Standard

1.x

C# 7.3

.NET Framework

All

C# 7.3

As you will see later in this book, you can override the default language version. You can do this by:

  • Manually editing your .csproj file (explained later).
  • Configuring multiple projects using a Directory.Build.props file.
  • Configuring the -langversion compiler option.

For more on the -langversion compiler option, refer to this .NET documentation.

C# version 1.0

The release of Visual Studio .NET 2002 brought with it C# 1.0, a Java-looking, general-purpose, object-oriented language. It didn’t contain LINQ or generics, but what it did offer developers was a viable alternative to Java, on a Windows platform.

C# 1.0 included the following:

  • Classes
  • Structs
  • Interfaces
  • Events
  • Properties
  • Delegates
  • Expressions
  • Statements
  • Attributes

Having a look at these features today, one would be excused for feeling a little spoiled with the features available in C# 8.0.

C# version 1.2

Visual Studio .NET 2003 shipped with C# 1.2 and only contained a few small feature enhancements. It is here that code generated in foreach loops would call Dispose on an IEnumerator if it implemented IDisposable.

C# version 2.0

When Visual Studio 2005 was released in 2005, we saw some nice features, such as:

  • Generics
  • Partial classes
  • Anonymous methods
  • Nullable value types
  • Iterators
  • Covariance and contravariance

Existing features were also improved, such as:

  • Getter/setter separate accessibility.
  • Method group conversions (simply assigning the name of a method to a delegate without using a new operator).
  • Static classes.
  • Delegate inference.

In many respects, C# 2.0 was a turning point in the language, especially with the introduction of generics and iterators.

C# version 3.0

In the latter part of 2007, Visual Studio 2008 was released. The language features it provided came with the release of the .NET Framework 3.5. These were as follows:

  • Auto-implemented properties.
  • Anonymous types.
  • Query expressions (LINQ).
  • Lambda expressions.
  • Expression trees.
  • Extension methods.
  • Implicitly typed local variables.
  • Partial methods.
  • Object and collection initializers.

LINQ was one of the killer features of C#. This allowed you to write SQL-style, declarative queries on collections, for example. Initially, I struggled with LINQ (and I’m not the only one). These days, it is just quicker and more concise to write. C# 3.0 was truly a groundbreaking release.

C# version 4.0

Visual Studio 2010 brought C# 4.0. The features added in version 4.0 were:

  • Dynamic binding.
  • Named/optional arguments.
  • Generic covariant and contravariant.
  • Embedded interop types.

For me, the introduction of optional parameters was a breath of fresh air, but it was the addition of the dynamic keyword in version 4.0 that stole the show.

C# version 5.0

C# version 5.0 was released with Visual Studio 2012 and made another groundbreaking addition to the C# language—the introduction of async and await for asynchronous programming. C# 5.0 introduced:

  • Asynchronous members
  • Caller info attributes

Asynchrony was now baked into C# as a first-class citizen.

C# version 6.0

Visual Studio 2015 brought C# version 6.0, and it is here that we started seeing smaller features that made developers more productive. These included:

  • using static (no more Console.this and Console.that).
  • Read-only auto-properties.
  • Auto-property initializers.
  • Expression-bodied function members.
  • Null-conditional operators.
  • String interpolation.
  • Exception filters.
  • The nameof expression.
  • await in Catch and Finally blocks.

I remember Mads Torgersen saying that C# 6.0 added a lot of syntactic sugar to the language. I agree with him 100 percent.

C# version 7.0

Visual Studio 2017 saw C# version 7.0 released to the developer community. It introduced the following language features:

  • out variables.
  • Tuples.
  • Discards.
  • Pattern matching.
  • ref locals and returns.
  • Local functions.
  • More expression-bodied members.
  • throw expressions.
  • Generalized async return types.
  • Numeric literal syntax improvements.

Developers could now write cleaner code and be more productive.

C# version 7.1

With C# 7.0, we started seeing point releases on C#, starting with version 7.1. This marked an increased release cadence for C#. New language features for this release were:

  • async Main method.
  • default literal expressions.
  • Inferred tuple element names.
  • Pattern matching on generic type parameters.

C# 7.1 also added the language version selection configuration element, as well as new compiler behavior.

C# version 7.2

C# 7.2 added a few more smaller language features to C#. These were:

  • The addition of code enhancements allowing developers to write safe, efficient code:
  • The in modifier on parameters.
  • The ref readonly modifier on method returns.
  • The readonly struct declaration.
  • The ref struct declaration.
  • Non-trailing named arguments.
  • Leading underscores in numeric literals.
  • private protected access modifier.
  • Conditional ref expressions.

You can read more on writing safe and efficient code in C# here.

C# version 7.3

The point releases of C# 7 allowed developers to get their hands onto new language features sooner rather than later. It was the release of C# 7.3 that had two main themes. One theme allowed safe code to be as performant as unsafe code, and the other provided additional improvements to existing features.

From a better performant safe code perspective, we saw:

  • The accessing of fields without pinning.
  • Reassigning ref local variables.
  • The use of initializers on stackalloc arrays.
  • Using fixed statements with any type that supports a pattern.
  • Additional generic constraints (you will see this in action with the unmanaged constraint later on in this book).

From an enhancement perspective, we saw:

  • Being able to compare tuple types with == and !=.
  • The use of expression variables in more locations.
  • Attaching attributes to the backing field of auto-implemented properties.
  • Improved method resolution when arguments differ by in.
  • Fewer ambiguous cases for overload resolution.

We also saw new compiler options: -publicsign to enable open-source software signing of assemblies, and -pathmap to provide a mapping for source directories.

C# version 8.0

C# 8.0 specifically targets .NET Core. This is what this book is all about, and why I would imagine you are reading it.

The following features and enhancements were added to C# 8.0:

  • Readonly members.
  • Default interface methods.
  • Pattern matching enhancements.
  • Using declarations.
  • Static local functions.
  • Disposable ref structs.
  • Nullable reference types.
  • Asynchronous streams.
  • Indices and ranges.
  • Null-coalescing assignment.
  • Unmanaged constructed types.
  • Stackalloc in nested types.
  • Enhancements to interpolated verbatim strings.

There is a lot to consume here. If you have little experience with C#, the best place to start is C# 7. This book will take a look at C# 7 before delving into the new features of C# 8.0.

If you are already comfortable with C# 7, then dive straight into the chapter on C# 8.0. Are you ready? Let’s go.

Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.