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}
}
No comments:
Post a Comment