Categories: C#

Features of C# 9.0

C# 9 was released in November 2020 as part of .NET 5. In this article, we will discuss some of the new features in C# 9.0.

C# 9 Major Features

Records

A record is a value type that represents an immutable data structure. Records allow you to define a type that is a lightweight alternative to a class, with automatic properties and a concise syntax for defining them.

Init-Only Properties

Init-only properties allow you to set the value of a property only during object initialization, making it easier to create immutable objects.

Top Level Statements

C# 9 introduces the ability to define statements at the top level of a file, allowing you to write short scripts or utilities without the need for a class or a Main method.

Target-Typed New Expressions

C# 9 allows you to omit the type of an object when calling the new operator, allowing the type to be inferred from the context.

Improved Pattern Matching

C# 9 includes several improvements to the pattern matching feature, including support for property patterns, record patterns, and positional patterns.

Improved Interpolated Strings

C# 9 includes several improvements to interpolated strings, including the ability to embed expressions directly in a string, and support for string interpolation in attribute arguments.

Asynchronous streams

C# 9 introduces the IAsyncEnumerable and IAsyncEnumerator interfaces, which allow you to define and consume asynchronous streams of data.

Improved module support

C# 9 includes several improvements to the support for modules, including the ability to import and export top-level statements, and the ability to specify module dependencies.

Improved Nullable Reference Types

C# 9 includes several improvements to the nullable reference types feature, including support for non-nullable reference types, and the ability to specify nullability for indexers and events.

Rajeev

Recent Posts

OWIN Authentication in .NET Core

OWIN (Open Web Interface for .NET) is an interface between web servers and web applications…

1 year ago

Serializing and Deserializing JSON using Jsonconvertor in C#

JSON (JavaScript Object Notation) is a commonly used data exchange format that facilitates data exchange…

1 year ago

What is CAP Theorem? | What is Brewer’s Theorem?

The CAP theorem is also known as Brewer's theorem. What is CAP Theorem? CAP theorem…

1 year ago

SOLID -Basic Software Design Principles

Some of the Key factors that need to consider while architecting or designing a software…

1 year ago

What is Interface Segregation Principle (ISP) in SOLID Design Principles?

The Interface Segregation Principle (ISP) is one of the SOLID principles of object-oriented design. The…

1 year ago

What is Single Responsibility Principle (SRP) in SOLID Design Priciples?

The Single Responsibility Principle (SRP), also known as the Singularity Principle, is a software design…

1 year ago