Part 2: C#7 features. What is new?

This article is the continuation of the previous article. Let us just start from where we have left off.

Expression Bodied Members

Though we were using short type expression before, new feature has bough some more functionality

lets consider the following class

The constructor declaration can be shorten like the following with the lambda expression

And now let’s see using Deconstructor

and to “set” and “get” and also

old way

new way

This specific thing has been contributed by the community rather than creating it by Microsoft.

Throw Expressions

Example of old way

New way

Throw statement and the assignment can be marched. like the following

Generalized Async Return Types

lets consider the following code

when it returns “0”, the task still continue. Consider the following

The new thing is “ValueTask” just to get the value.


Out Variables

Out variable type can be declared at the time when it is in use.

Pattern Matching

pattern matching and be checked and declared at the same time and also can be used F# type “When” variable.


Name can be preserved exclusively and return type can be directed to the different variables simply.

Local Functions

Function can be written anywhere

Ref Returns & Locals

Ref can be fetched and referenced to a variable and can point without any validity check whether that thing existing.

Expression Bodied Members

Shorter way of using Lambda

Throw Expressions

Can write within the same logic

Generalized Async Return Types

Introduced ValueTask.


Leave a Reply

Your email address will not be published. Required fields are marked *