C# 10 in a Nutshell

Joseph Albahari

June 01, 2022 2. C# Language Basics

You can insert an underscore anywhere within a numeric literal to make it more readable:

June 01, 2022 2. C# Language Basics

decrementing the minimum possible int value results in the maximum possible int value:

June 12, 2022 2. C# Language Basics

The ??= operator (introduced in C# 8) is the null-coalescing assignment operator. It says, “If the operand to the left is null, assign the right operand to the left operand.”

September 24, 2022 2. C# Language Basics

You can also switch on multiple values (the tuple pattern):

September 24, 2022 2. C# Language Basics

From .NET 6, project files allow for implicit global using directives. If the Implici⁠t​Usings element is set to true in the project file (the default for new projects), the following namespaces are automatically imported: System System.Collections.Generic System.IO System.Linq System.Net.Http System.Threading System.Threading.Tasks Additional namespaces are imported, based on the project SDK (Web, Windows Forms, WPF, and so on)

September 24, 2022 2. C# Language Basics

Extern aliases allow your program to reference two types with the same fully qualified name (i.e., the namespace and type name are identical). This is an unusual scenario and can occur only when the two types come from different assemblies.

September 24, 2022 3. Creating Types in C#

A constant can serve a similar role to a static readonly field, but it is much more restrictive—both in the types you can use and in field initialization semantics. A constant also differs from a static readonly field in that the evaluation of the constant occurs at compile time

September 24, 2022 3. Creating Types in C#

the following pairs of methods cannot coexist in the same type, because the return type and the params modifier are not part of a method’s signature

September 24, 2022 3. Creating Types in C#

Whether a parameter is pass-by-value or pass-by-reference is also part of the signature

September 24, 2022 3. Creating Types in C#

A deconstructor (also called a deconstructing method) acts as an approximate opposite to a constructor: whereas a constructor typically takes a set of values (as parameters) and assigns them to fields, a deconstructor does the reverse and assigns fields back to a set of variables.

September 25, 2022 3. Creating Types in C#

this approach makes versioning difficult, in that adding an optional parameter to the constructor at a later date breaks binary compatibility with consumers (whereas adding a new init-only property breaks nothing).

September 25, 2022 3. Creating Types in C#

From C# 9, you can override a method (or property get accessor) such that it returns a more derived (subclassed) type.

September 25, 2022 3. Creating Types in C#

If a constructor in a subclass omits the base keyword, the base type’s parameterless constructor is implicitly called

September 25, 2022 3. Creating Types in C#

Boxing is the act of converting a value-type instance to a reference-type instance

Updated:

Leave a comment