You are here
Home > Programming > Enabling C# 8 in Visual Studio 2019

Enabling C# 8 in Visual Studio 2019

using c# 8 in visual studio 2019

We can probably all agree that C# 8.0 is a version of the language packed with many new features. The problem is that some developers think that you can only use C# 8 if you are using .NET Core 3 or .NET Standard 2.1. That’s not entirely true. Enabling C# 8 in any .NET project is easier than you think. Here’s how.

LOOKING FOR SOMETHING ELSE? TRY THESE LINKS INSTEAD:

If you are short on time, check out the video tutorial on how to enable C# 8 in Visual Studio 2019.

If you like the video, leave a comment.

Start using C# 8 in Any .NET Project

To start using C# 8 in your .NET Projects, you will need to modify your csproj file. Look for the LangVersion tag and change it as follows:

<LangVersion>8.0</LangVersion>

Here is what it should look like.

csproj file with langversion modified to target C# 8

This is all there is to it. There are some proviso’s though.

Some C# 8 Types Not Included

Some types such as IAsyncEnumerable are not included. There is a workaround though. Remember how developers needed to install a NuGet package to bring in ValueTulple? Well, you can do the same here.

Just swing on over to NuGet and get Microsoft.Bcl.AsyncInterfaces and Microsoft.Bcl.HashCode.

Indexes and Ranges Limitation

Using C# 8 in non-.NET Core 3 or .NET Standard 2.1 projects does have some limitations. But these are few and far between. For example, indexes and ranges are runtime features and this means that they will not be available to you. If you try to use these, your code will simply not compile.

Should you Enable C# 8?

Enabling C# 8 in any .NET Project is super easy. If you can live with the limitations and exclusions of some types, there is no reason why you shouldn’t try using C# 8. If you are not familiar with all the features of C# 8, then have a look at the following list.

C# 8 Features

Here are some of the new features and enhancements to C# 8:

  • Readonly members
  • Default interface methods
  • Pattern matching enhancements:
    • Switch expressions
    • Property patterns
    • Tuple patterns
    • Positional patterns
  • 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 expressions
  • Enhancement of interpolated verbatim strings

During the coming weeks, we will explore some of these new C# 8 features, so stay tuned.

Dirk Strauss
Dirk is a Software Developer and Microsoft MVP from South Africa. He loves all things Technology and is slightly addicted to Twitter and Jimi Hendrix. Apart from writing code, he also enjoys writing human readable articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has yet to master.

Similar Articles

Top