c# no more boiler plate code for assigning value to properties
With c# record, no longer have to do manual instantiation or setting property when passing value as part of the constructor, for example, using the following
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Is the 'almost' equivalent of
public class WeatherForecast
{
public int TemperatureC { get; set; }
public int Date { get; set; }
public string Summary { get; set; }
public WeatherForecast(DateOnly date, int temperatureC, string? summary)
{
Summary = summary;
Date = date;
TemperatureC = temperatureC;
}
}
Comments