1
Reply

What is a primary constructor C# 6.0?

Santosh Kumar Adidawarpu

Santosh Kumar Adidawarpu

May 08, 2016
275
0

    Primary constructor is introduced in C# 6.0.It allows you to assign a value to an auto-property at declaration time only, just as with a field. Without primary constructor:public class Student {public int Id{ get; private set; }public Name { get; private set; }public Student(int id, string name){Id = id;Name = name;} }With primary constructor:public class Student {public Student(int id, string name){public int Id{ get; } = id;public Name { get;} = name;} }