Records

  • Records are immutable by default.
  • All the record members are init-only properties.
				
					
record EmployeeDTO(int EmpId, string EmployeeName);

//This record is similar to below class

/*
class EmployeeDTO
{
    public int EmpID { get; set; }
    public string EmployeeName { get; set; }

    public EmployeeDTO1(string employeeName, int empID)
    {
        EmployeeName = employeeName;
        EmpID = empID;
    }
}
*/
				
			
  • init only property can only be assigned only in constructor or object-initializer.

Leave a Comment