What’s new in .NET Framework 5.0

Asad Iftikhar
4 min readJun 23, 2021

.NET Frame work is next release from .net core 3.0 but it is named .net 5.0 cause it is available except .net core projects in . net Framework

Top Level Statement’s : -

This C# 9.0 feature mainly works in Console Application where you have one class basically this features allow you to remove namespaces class name and directly write the code which needs to be performed.

Practical Implementation : -

For this features to work your visual studio must have .NET Frame work 5.0 and C# 9.0

The Code after Running gives the following output

Records : -

C# 9.0 provides a new feature call Records through which you can make Properties immutable means you can just Initialize the Values of object one time after that it’s Un Changeable.

Practical Implementation : -

The Result After One time Initialization of Value is

Now, When will change Declare Object Property of Name it does not make me change it!!

You will achieve this error!!

Severity Code Description Project File Line Suppression State

Error CS8852 Init-only property or indexer ‘RecordsImplementation.Product.Name’ can only be assigned in an object initializer, or on ‘this’ or ‘base’ in an instance constructor or an ‘Init’ accessor. ConsoleApp2

With Expression : -

You can use With expression when you have an Object Declared and you want to declare Second Object identical to First with Some or All Values Changed

Syntax : -

Object obj2= obj1 with { Parameters need to be changes};

Practical Implementation : -

You can achieve this output

Object Based Comparison : -

In C# 9.0 we can achieve Value Based Comparison which will compares two Object Value. Instead of Reference Based Comparison which will compare two Objects.

Practical Implementation : -

You can achieve this output!!

Difference Between Records and Class : -

Records is just another fancy class with more functionality than Class

We can use Records when we need to pass data from one application to another application With class we need to create class on both Sides or JsonConvert.SerializeObject(classObject) but Records you can simply pass records and you don’t have to define records on both sides for getting Property values

Practical Implementation : -

Hash Code (Memory Difference) between Records And Class : -

If the Two Objects are in Values then the Class with Stores these two Objects on CPU different Memory address but when we use Records if two Objects Values and Number of Properties are same then it will save it in One Address

Practical Implementation : -

As Records are Immutable we can Initialize some Values in Records directly which not require to be Initialized by the User

For Example :- Full Name which is comparison of FirstName and Last Name

Practical Implementation : -

Output :-

--

--