C#的正确版本号是什么?什么时候出来?为什么我找不到关于 C#3.5 的答案?
这个问题主要是为了帮助那些使用不正确的版本号搜索答案的人,例如 C#3.5 。希望任何未能找到错误版本号的答案的人都会找到此问题,然后再使用正确的版本号进行搜索。
答案 0 :(得分:2672)
这些是撰写本文时已知的versions of C#:
Dispose
的{{1}}上调用IEnumerator
的第一个版本。其他一些小功能。IDisposable
),查询表达式var
),委托和接口泛型差异,更多COM支持,命名参数,元组数据类型和可选参数dynamic
中的await
和catch
,扩展finally
方法在集合初始化器中。out
parameter declarations,local functions,binary literals, digit separators和arbitrary async returns。unmanaged
generic type constraints。 Add
重新分配。不安全的改进:ref
初始化,取消固定的索引stackalloc
缓冲区,自定义fixed
语句。改进了重载分辨率。初始化器和查询中的表达式变量。为元组定义fixed
和==
。现在,属性可以定位自动属性的支持字段。!=
支持,范围和默认界面方法。C#的正确版本号是什么?什么时候出来?为什么我找不到关于C#3.5的任何答案?
没有C#3.5之类的东西 - 这里引起混淆的原因是.NET 3.5中存在C#3.0。然而,语言和框架是独立版本的 - 就像CLR一样,.NET 2.0到.NET 2.0版本为2.0,.NET 4引入了CLR 4.0,尽管服务包也是如此。 .NET 4.5中的CLR有各种改进,但版本控制还不清楚:在某些地方它可能被称为CLR 4.5(this MSDN page用于以这种方式引用它,例如),但是{{3属性仍然报告4.0.xxx。
Environment.Version
网站上提供了有关语言,运行时和框架版本之间关系的更多详细信息。这包括有关在面向.NET 2.0时可以使用哪些C#3.0功能的信息。 (如果有人想将所有内容都纳入此维基答案,欢迎他们参加。)
截至2017年5月3日,C#语言团队在其github repo上创建了C#版本和功能的历史记录:C# in Depth。还有Features Added in C# Language Versions。
答案 1 :(得分:281)
处理C#的版本号时最大的问题是它与.NET Framework的版本无关,它似乎是由于Visual Studio和.NET Framework之间的同步版本所致。 p>
C#的版本实际上绑定到编译器,而不是框架。例如,在Visual Studio 2008中,您可以编写C#3.0并以.NET Framework 2.0,3.0和3.5为目标。 C#3.0命名法描述了代码语法和支持的功能的版本,与ANSI C89, C90, C99描述C的代码语法/功能的方式相同。
看看Mono,你会发现Mono 2.0(主要是从ECMA规范实现的.NET Framework 2.0版本)支持C#3.0语法和功能。
答案 2 :(得分:265)
这与大多数答案相同,但是为了方便而制表,并且它具有Visual Studio和.NET版本以实现完整性。
╔════════════╦════════════╦══════════════╦═════════════╦══════════════╗
║ C# version ║ VS version ║ .NET version ║ CLR version ║ Release date ║
╠════════════╬════════════╬══════════════╬═════════════╬══════════════╣
║ 1.0 ║ 2002 ║ 1.0 ║ 1.0 ║ Feb 2002 ║
║ 1.2 ║ 2003 ║ 1.1 ║ 1.1 ║ Apr 2003 ║
║ 2.0 ║ 2005 ║ 2.0 ║ 2.0 ║ Nov 2005 ║
║ ║ ║ 3.0 ║ 2.0 ║ Nov 2006 ║
║ 3.0 ║ 2008 ║ 3.5 ║ 2.0 ║ Nov 2007 ║
║ 4.0 ║ 2010 ║ 4.0 ║ 4 ║ Apr 2010 ║
║ 5.0 ║ 2012 ║ 4.5 ║ 4 ║ Aug 2012 ║
║ 5.0 ║ 2013 ║ 4.5.1 ║ 4 ║ Oct 2013 ║
║ ║ ║ 4.5.2 ║ 4 ║ May 2014 ║
║ 6.0 ║ 2015 ║ 4.6 ║ 4 ║ Jul 2015 ║
║ ║ ║ 4.6.1 ║ 4 ║ Nov 2015 ║
║ ║ ║ 4.6.2 ║ 4 ║ Aug 2016 ║
║ 7.0 ║ 2017 ║ ║ ║ Mar 2017 ║
║ ║ ║ 4.7 ║ 4 ║ May 2017 ║
║ 7.1 ║ 2017(v15.3)║ ║ ║ Aug 2017 ║
║ ║ ║ 4.7.1 ║ 4 ║ Oct 2017 ║
║ 7.2 ║ 2017(v15.5)║ ║ ║ Dec 2017 ║
║ ║ ║ 4.7.2 ║ 4 ║ Apr 2018 ║
║ 7.3 ║ 2017(v15.7)║ ║ ║ May 2018 ║
║ 8.0 ║ 2019 ║ ║ ║ Apr 2019 ║
╚════════════╩════════════╩══════════════╩═════════════╩══════════════╝
注意:.NET开发现在几乎与VS无关,每个版本之间没有相关性。请参阅" .NET Framework versions and dependencies"更多。
答案 3 :(得分:182)
C#1.0
使用Visual Studio 2005C#2.0
C#3.0
C#4.0
C#5.0
C#6.0
C#7.0
答案 4 :(得分:75)
VERSION _____
语言规范______
MICROSOFT COMPILER
C#1.0 / 1.2 ____
2001年12月? / 2003 ? ___________
2002年1月 ?
C#2.0 _______
September 2005 ________________
2005年11月?
C#3.0 _______
May 2006 _____________________
2006年11月?
C#4.0 _______
March 2009 (draft) ______________
2010年4月?
C#5.0;于2012年8月与.NET 4.5一起发布
C#6.0;随.NET 4.6 2015发布
C#7.0;随.NET 4.7 2017发布
答案 5 :(得分:51)
C#版本历史记录:
C#是一种简单而强大的面向对象编程语言,由Microsoft开发。
自2002年首次发布以来,C#已经发展很多。随着.NET Framework 1.0引入了C#。
下表列出了每个C#版本中引入的重要功能。
最新版本的C#可在 C# Versions 中找到。
答案 6 :(得分:46)
我总结了此表中的大多数版本。唯一缺少的应该是ASP.NET Core版本。我还添加了不同版本的ASP.NET MVC。
请注意,ASP.NET 5已更名为ASP.NET Core 1.0,ASP.NET MVC 6已更名为ASP.NET Core MVC 1.0.0。我相信这种变化发生在2016年1月左右。
我已经在表格中包含了ASP.NET 5 RC1的发布日期,但我还没有包含ASP.NET核心1.0和其他核心版本,因为我无法找到确切的发布日期。您可以在此处阅读有关ASP.NET Core的发布日期的更多信息: When is ASP.NET Core 1.0 (ASP.NET 5 / vNext) scheduled for release?
答案 7 :(得分:43)
您可以查看最新的C#版本here
答案 8 :(得分:31)
比较MSDN文章"What's New in the C# 2.0 Language and Compiler"和“What's New in Visual C# 2005”,可以推断“C#major_version.minor_version”是根据编译器的版本编号创造的。
有C# 1.2 corresponding to .NET 1.1 and VS 2003,也有Visual C# .NET 2003。
但是,微软进一步停止增加次要版本(点数之后)数字或使其不为零0
。虽然应该注意,对应于.NET 3.5的C#在msdn.microsoft.com中以"Visual C# 2008 Service Pack 1"命名。
有两个并行命名:主要的.NET /编译器版本编号和Visual Studio编号。
的同义词C#3.0对应(或更准确地说,可以定位):
答案 9 :(得分:6)
Version .NET Framework Visual Studio Important Features
C# 1.0 .NET Framework 1.0/1.1 Visual Studio .NET 2002
Basic features
C# 2.0 .NET Framework 2.0 Visual Studio 2005
Generics
Partial types
Anonymous methods
Iterators
Nullable types
Private setters (properties)
Method group conversions (delegates)
Covariance and Contra-variance
Static classes
C# 3.0 .NET Framework 3.0\3.5 Visual Studio 2008
Implicitly typed local variables
Object and collection initializers
Auto-Implemented properties
Anonymous types
Extension methods
Query expressions
Lambda expressions
Expression trees
Partial Methods
C# 4.0 .NET Framework 4.0 Visual Studio 2010
Dynamic binding (late binding)
Named and optional arguments
Generic co- and contravariance
Embedded interop types
C# 5.0 .NET Framework 4.5 Visual Studio 2012/2013
Async features
Caller information
C# 6.0 .NET Framework 4.6 Visual Studio 2013/2015
Expression Bodied Methods
Auto-property initializer
nameof Expression
Primary constructor
Await in catch block
Exception Filter
String Interpolation
C# 7.0 .NET Core 2.0 Visual Studio 2017
out variables
Tuples
Discards
Pattern Matching
Local functions
Generalized async return types
Numeric literal syntax improvements
C# 8.0 .NET Core 3.0 Visual Studio 2019
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
Asynchronous disposable
Indices and ranges
Null-coalescing assignment
Unmanaged constructed types
Stackalloc in nested expressions
Enhancement of interpolated verbatim strings
答案 10 :(得分:3)
Classes
Structs
Interfaces
Events
Properties
Delegates
Expressions
Statements
Attributes
Literals
Dispose in foreach
foreach over string specialization
C# 2 - Visual Studio 2005
Generics
Partial types
Anonymous methods
Iterators
Nullable types
Getter/setter separate accessibility
Method group conversions (delegates)
Static classes
Delegate inference
Implicitly typed local variables
Object and collection initializers
Auto-Implemented properties
Anonymous types
Extension methods
Query expressions
Lambda expression
Expression trees
Partial methods
Dynamic binding
Named and optional arguments
Co- and Contra-variance for generic delegates and interfaces
Embedded interop types ("NoPIA")
Asynchronous methods
Caller info attributes
Draft Specification online
Compiler-as-a-service (Roslyn)
Import of static type members into namespace
Exception filters
Await in catch/finally blocks
Auto property initializers
Default values for getter-only properties
Expression-bodied members
Null propagator (null-conditional operator, succinct null checking)
String interpolation
nameof operator
Dictionary initializer
Out variables
Pattern matching
Tuples
Deconstruction
Discards
Local Functions
Binary Literals
Digit Separators
Ref returns and locals
Generalized async return types
More expression-bodied members
Throw expressions
Async main
Default expressions
Reference assemblies
Inferred tuple element names
Pattern-matching with generics
Span and ref-like types
In parameters and readonly references
Ref conditional
Non-trailing named arguments
Private protected accessibility
Digit separator after base specifier
System.Enum, System.Delegate and unmanaged constraints.
Ref local re-assignment: Ref locals and ref parameters can now be reassigned with the ref assignment operator (= ref).
Stackalloc initializers: Stack-allocated arrays can now be initialized, e.g. Span<int> x = stackalloc[] { 1, 2, 3 };.
Indexing movable fixed buffers: Fixed buffers can be indexed into without first being pinned.
Custom fixed statement: Types that implement a suitable GetPinnableReference can be used in a fixed statement.
Improved overload candidates: Some overload resolution candidates can be ruled out early, thus reducing ambiguities.
Expression variables in initializers and queries: Expression variables like out var and pattern variables are allowed in field initializers, constructor initializers and LINQ queries.
Tuple comparison: Tuples can now be compared with == and !=.
Attributes on backing fields: Allows [field: …] attributes on an auto-implemented property to target its backing field.
Nullable reference types: express nullability intent on reference types with ?, notnull constraint and annotations attributes in APIs, the compiler will use those to try and detect possible null values being dereferenced or passed to unsuitable APIs.
Default interface members: interfaces can now have members with default implementations, as well as static/private/protected/internal members except for state (ie. no fields).
Recursive patterns: positional and property patterns allow testing deeper into an object, and switch expressions allow for testing multiple patterns and producing corresponding results in a compact fashion.
Async streams: await foreach and await using allow for asynchronous enumeration and disposal of IAsyncEnumerable<T> collections and IAsyncDisposable resources, and async-iterator methods allow convenient implementation of such asynchronous streams.
Enhanced using: a using declaration is added with an implicit scope and using statements and declarations allow disposal of ref structs using a pattern.
Ranges and indexes: the i..j syntax allows constructing System.Range instances, the ^k syntax allows constructing System.Index instances, and those can be used to index/slice collections.
Null-coalescing assignment: ??= allows conditionally assigning when the value is null.
Static local functions: local functions modified with static cannot capture this or local variables, and local function parameters now shadow locals in parent scopes.
Unmanaged generic structs: generic struct types that only have unmanaged fields are now considered unmanaged (ie. they satisfy the unmanaged constraint).
Readonly members: individual members can now be marked as readonly to indicate and enforce that they do not modify instance state.
Stackalloc in nested contexts: stackalloc expressions are now allowed in more expression contexts.
Alternative interpolated verbatim strings: @$"..." strings are recognized as interpolated verbatim strings just like $@"...".
Obsolete on property accessors: property accessors can now be individually marked as obsolete.
Permit t is null on unconstrained type parameter
[源代码]: https://github.com/dotnet/csharplang/blob/master/Language-Version-History.md
答案 11 :(得分:3)
C#8.0是c#的最新版本。仅.NET Core 3.x和更高版本支持它。许多最新功能需要.NET Core 3.x
中引入的库和运行时功能。下表列出了目标框架及其版本和默认的C#版本。
答案 12 :(得分:1)
我正在寻找 .NET、C#、CLR、VS 版本以及主要语言功能的简明历史。
因为我找不到任何包含我需要的所有信息的最新表格 - 我将 Microsoft 文档中的详细信息合并到我试图保留一个包含我正在寻找的内容的简洁表格中.
可在此处获取:https://mantinband.github.io/dotnet-shmotnet/
我可能有一些错误或缺少信息,所以请随时在此处打开问题或贡献:https://github.com/mantinband/dotnet-shmotnet
先睹为快:
答案 13 :(得分:0)
这些是在撰写本文时已知的versions of C#:
Dispose
的{{1}}上调用IEnumerator
的第一个版本。其他一些小功能。IDisposable
),查询表达式
- C#3.5 没有这样的东西,.NET 3.5中存在C#3.0,请不要混淆!!!
var
),委托和接口通用方差,更多的COM支持,命名参数,元组数据类型和可选参数dynamic
中的await
和catch
的扩展finally
方法在集合初始化程序中。out
parameter declarations,local functions,binary literals, digit separators和arbitrary async returns。unmanaged
generic type constraints。 Add
重新分配。不安全的改进:ref
初始化,未固定索引的stackalloc
缓冲区,自定义fixed
语句。改进的重载分辨率。初始化程序和查询中的表达式变量。为元组定义了fixed
和==
。自动属性的后备字段现在可以通过属性作为目标。!=
支持,范围和默认接口方法。