-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 |
---|---|
default | The compiler accepts all valid language syntax from the latest major version that it can support. |
ISO-1 | The compiler accepts only syntax that is included in ISO/IEC 23270:2003 C# (1.0/1.2) ISO1 |
ISO-2 | The compiler accepts only syntax that is included in ISO/IEC 23270:2006 C# (2.0) ISO2 |
3 | The compiler accepts only syntax that is included in C# 3.0 or lower CS3 |
4 | The compiler accepts only syntax that is included in C# 4.0 or lower CS4 |
5 | The compiler accepts only syntax that is included in C# 5.0 or lower CS5 |
6 | The compiler accepts only syntax that is included in C# 6.0 or lower CS6 |
7 | The compiler accepts only syntax that is included in C# 7.0 or lower CS7 |
7.1 | The compiler accepts only syntax that is included in C# 7.1 or lower CS71 |
7.2 | The compiler accepts only syntax that is included in C# 7.2 or lower CS72 |
7.3 | The compiler accepts only syntax that is included in C# 7.3 or lower CS73 |
latest | The compiler accepts all valid language syntax that it can support. |
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# 1.0 | Download DOC | C# Language Specification Version 1.0: Microsoft Corporation |
C# 1.2 | Download DOC | C# Language Specification Version 1.2: Microsoft Corporation |
C# 2.0 | Download PDF | Standard ECMA-334 4th Edition |
C# 3.0 | Download DOC | C# Language Specification Version 3.0: Microsoft Corporation |
C# 5.0 | Download PDF | Standard ECMA-334 5th Edition |
C# 6.0 | Link | C# Language Specification Version 6 - Unofficial Draft: .NET Foundation |
C# 7.0 and later | not currently available |
Minimum compiler version needed to support all language features
↩ISO1: Microsoft Visual Studio/Build Tools .Net 2002 or bundled .Net Framework 1.0 compiler ↩ISO2: Microsoft Visual Studio/Build Tools 2005 or bundled .Net Framework 2.0 compiler ↩CS3: Microsoft Visual Studio/Build Tools 2008 or bundled .Net Framework 3.5 compiler ↩CS4: Microsoft Visual Studio/Build Tools 2010 or bundled .Net Framework 4.0 compiler ↩CS5: Microsoft Visual Studio/Build Tools 2012 or bundled .Net Framework 4.5 compiler ↩CS6: Microsoft Visual Studio/Build Tools 2015 ↩CS7: Microsoft Visual Studio/Build Tools 2017 ↩CS71: Microsoft Visual Studio/Build Tools 2017, version 15.3 ↩CS72: Microsoft Visual Studio/Build Tools 2017, version 15.5 ↩CS73: Microsoft Visual Studio/Build Tools 2017, version 15.7
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...