Language features by version

This book is mostly organized by version, but it can be difficult to get a sense of the features introduced in each version at a glance. This is particularly true for the features introduced in minor versions of C# 7, which typically improve a feature introduced in C# 7.0.

Additionally, it can be useful to know whether a language feature requires runtime or framework support or whether it’s pure compiler magic. This appendix aims to make all of this information available as simply as possible.

One aspect I haven’t mentioned is how generic type inference has evolved over versions. It’s changed many times and usually in ways that are too complicated to capture in just a few words. I suggest you take it as a given that anytime a new version is introduced, generic type inference may have improved.

Feature

Notes and requirements

Section

C# 2
Generics Runtime and framework support required. 2.1
Nullable value types Runtime and framework support required. 2.2
Method group conversions   2.3.1
Anonymous methods   2.3.2
Delegate covariance and contravariance[a]   2.3.3
Iterators (yield return)   2.4
Partial types   2.5.1
Static classes   2.5.2
Separate getter/setter access on properties   2.5.3
Namespace alias qualifier :: syntax   2.5.4
The global namespace alias   2.5.4
Extern aliases   2.5.5
Fixed-size buffers   2.5.6
InternalsVisibleToAttribute support Runtime and framework support required. 2.5.7
C# 3
Partial methods   2.5.1
Automatically implemented properties   3.1
Implicitly typed local variables (var)   3.2.2
Implicitly typed arrays (new[])   3.2.3
Object initializers   3.3.2
Collection initializers   3.3.3
Anonymous types   3.4
Lambda expressions (delegates)   3.5
Lambda expressions (expression trees) Framework support required (expression tree types). 3.5.3
Extension methods Framework support required (attribute). 3.6
Query expressions   3.7
C# 4
Dynamic typing Framework support required (called the Dynamic Language Runtime but not part of the runtime). 4.1
Optional parameters   4.2
Named arguments   4.2
Linked primary interop assemblies Runtime and framework support required. 4.3.1
Special rules for optional parameters in COM   4.3.2
Access to named indexers (COM only)   4.3.3
Generic variance for interfaces and delegates Framework changes to existing interfaces and delegates. (Runtime support was already present.) 4.4
Implementation change to lock statements Framework support required: Monitor.Enter(object, ref bool). Third edition, section 13.4.1
Implementation changes to field-like events   Third edition, section 13.4.2
Field-like event access within the declaring class   Third edition, section 13.4.2
C# 5
Async/await Framework support (task types and additional infrastructure used by the compiler). Chapters 5 and 6
Changes to foreach iteration variable capture Change in behavior, but only for code that was almost certainly broken in previous versions. 7.1
Caller information attributes Framework support (the attributes themselves). 7.2
C# 6
Read-only automatically implemented properties   8.2.1
Initializers for automatically implemented properties   8.2.2
Remove requirement to call this() in constructors for structs containing automatically implemented properties   8.2.3
Expression-bodied members   8.3
Interpolated string literals Additional support for FormattableString when that class and FormattableStringFactory are available. 9.2, 9.3
The nameof operator   9.5
The using static directive   10.1
Object initializers using indexers   10.2.1
Collection initializers using extension Add methods   10.2.2
The null conditional ?. operator   10.3
Exception filters   10.4
Removed restrictions on awaiting in try/catch, try/finally, and try/catch statements   5.4.2
C# 7.0
Tuples Framework support (ValueTuple types). 11.2–11.4
Deconstruction via Deconstruct methods Required ValueTuple types to be present until C# 7.2 compiler, but not a C# 7.2 language feature. (Implementation change, effectively.) 12.1, 12.2
Initial patterns: constant patterns, type patterns, var patterns   12.4
Use of patterns with the is operator   12.5
Use of patterns in switch statements, including guard clauses (when)   12.6
Ref locals   13.2.1
Ref return   13.2.2
Binary integer literals   14.3.1
Underscore separators in numeric literals   14.3.2
Returning custom task types from async methods Framework support required (attributes). 5.8
More kinds of expression-bodied members   8.3.3
C# 7.1
The default literal   14.5
Improvements to type patterns matching against generic values   12.4.2
Async entry points (async Task Main)   5.9
Inferred tuple element names   11.2.2
C# 7.2
Allow the conditional ?: operator to work with ref   13.2.3
ref readonly locals and return types Methods returning ref readonly can be called only by compilers that understand them. Additionally, InAttribute is required at compile time but has been present since .NET 1.1 and .NET Standard 1.1. 13.2.4
in parameters Requires IsReadOnlyAttribute, but that’s bundled in the output if it’s missing from the target framework. 13.3
Read-only structs Requires IsReadOnlyAttribute as noted the preceding entry. 13.4
Extension methods with ref/in parameters   13.5
Ref-like structs Requires IsReadOnlyAttribute as noted previously. Additionally, ref-like structs have ObsoleteAttribute applied to them with a specific message. Ref-like-struct-aware compiler versions ignore this, but earlier compilers will prevent the type being used. 13.6
stackalloc support for Span<T> Framework support required. 13.6.2
Nontrailing named arguments   14.6
The private protected access modifier   14.7
Underscore separators in numeric literals directly after the 0x or 0b base specifier   14.3.2
C# 7.3
Access to fixed-sized buffers via fields without fixed statements   2.5.6
== and != operators for tuples Availability of tuples, but no new requirements. 11.3.6
Use of pattern and out variables in field, property, and constructor initializers   14.2.2
Reassignment of ref locals   13.2.1
Initializers in stackalloc statements   13.6.2
Pattern-based fixed statements using GetPinnableReference   13.6.2
Generic type constraints now permitted on Enum and Delegate   14.8.1
New generic type constraint of unmanaged Types and methods with the unmanaged constraint can be used only by compilers recent enough to understand it. Also required UnmanagedType enum, available since .NET 1.1 and .NET Standard 1.1. 14.8.1
Placement of attributes of fields backing automatically implemented properties   14.8.3

a

This refers to constructing a delegate from a method with a compatible but not identical signature. This isn’t the same as generic variance introduced in C# 4.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset