Saturday 12 November 2022

Concise way of declaring constructor in C#

 The Concise way of declaring a constructor in C# is also called the Expression bodied  Constructor 


In the previous, we are declaring a constructor like this 


public class Person 

{

public string Name {get;}

public int Age{get;}

public Person(string name, int age){

Name=name;

Age=age;

}

}

But now we can declare the more concise way of declaring a constructor in C#

Public class Person

{

public string Name{get;}

public int Age{get;}

public Person(string name, int age)=>(Name,Age)={name,age}

}

AdSense

The Ultimate Guide to Interceptors: Understanding Their Power and Functionality

  The Ultimate Guide to Interceptors: Understanding Their Power and Functionality An interceptor is a service that can intercept HTTP reques...

Follow