-langversion (C# Compiler Options)

Causes the compiler to accept only syntax that is included in the chosen C# language specification.

Syntax

-langversion:option  

Arguments

option
The following values are valid:

Option Meaning
preview The compiler accepts all valid language syntax from the latest preview version that it can support.
latest The compiler accepts all valid language syntax from the latest version (including minor releases) that it can support.
latestMajor The compiler accepts all valid language syntax from the latest major version that it can support.
8.0 The compiler accepts only syntax that is included in C# 8.0 or lower. CS80
7.3 The compiler accepts only syntax that is included in C# 7.3 or lower CS73
7.2 The compiler accepts only syntax that is included in C# 7.2 or lower CS72
7.1 The compiler accepts only syntax that is included in C# 7.1 or lower CS71
7 The compiler accepts only syntax that is included in C# 7.0 or lower CS7
6 The compiler accepts only syntax that is included in C# 6.0 or lower CS6
5 The compiler accepts only syntax that is included in C# 5.0 or lower CS5
4 The compiler accepts only syntax that is included in C# 4.0 or lower CS4
3 The compiler accepts only syntax that is included in C# 3.0 or lower CS3
ISO-2 The compiler accepts only syntax that is included in ISO/IEC 23270:2006 C# (2.0) ISO2
ISO-1 The compiler accepts only syntax that is included in ISO/IEC 23270:2003 C# (1.0/1.2) ISO1

The default language version depends on the target framework for your application and the version of the SDK or Visual Studio installed. Those rules are defined in the article on configuring the language version

Remarks

Metadata referenced by your C# application is not subject to -langversion compiler option.

Because each version of the C# compiler contains extensions to the language specification, -langversion does not give you the equivalent functionality of an earlier version of the compiler.

Additionally, while C# version updates generally coincide with major .NET Framework releases, the new syntax and features are not necessarily tied to that specific framework version. While the new features definitely require a new compiler update that is also released alongside the C# revision, each specific feature has its own minimum .NET API or common language runtime requirements that may allow it to run on downlevel frameworks by including NuGet packages or other libraries.

Regardless of which -langversion setting you use, you will use the current version of the common language runtime to create your .exe or .dll. One exception is friend assemblies and -moduleassemblyname (C# Compiler Option), which work under -langversion:ISO-1.

For other ways to specify the C# language version, see the Select the C# language version topic.

For information about how to set this compiler option programmatically, see LanguageVersion.

See also

C# Language Specification

Version Link Description
C# 7.0 and later not currently available
C# 6.0 Link C# Language Specification Version 6 - Unofficial Draft: .NET Foundation
C# 5.0 Download PDF Standard ECMA-334 5th Edition
C# 3.0 Download DOC C# Language Specification Version 3.0: Microsoft Corporation
C# 2.0 Download PDF Standard ECMA-334 4th Edition
C# 1.2 Download DOC C# Language Specification Version 1.2: Microsoft Corporation
C# 1.0 Download DOC C# Language Specification Version 1.0: Microsoft Corporation

Minimum compiler version needed to support all language features

CS80: Microsoft Visual Studio/Build Tools 2019, version 16, or .NET Core 3.0 SDK
CS73: Microsoft Visual Studio/Build Tools 2017, version 15.7
CS72: Microsoft Visual Studio/Build Tools 2017, version 15.5
CS71: Microsoft Visual Studio/Build Tools 2017, version 15.3
CS7: Microsoft Visual Studio/Build Tools 2017
CS6: Microsoft Visual Studio/Build Tools 2015
CS5: Microsoft Visual Studio/Build Tools 2012 or bundled .NET Framework 4.5 compiler
CS4: Microsoft Visual Studio/Build Tools 2010 or bundled .NET Framework 4.0 compiler
CS3: Microsoft Visual Studio/Build Tools 2008 or bundled .NET Framework 3.5 compiler
ISO2: Microsoft Visual Studio/Build Tools 2005 or bundled .NET Framework 2.0 compiler
ISO1: Microsoft Visual Studio/Build Tools .NET 2002 or bundled .N Framework 1.0 compiler