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

Chand

  मुझे चाँद देखना पसंद है, उसे चाँद सा दिखना पसंद है। वो भी अपने दाग नहीं छुपाती, आँखों में काजल, माथे पे बिंदी नहीं लगाती। होठों को उन्...

Follow