Here we are going to learn to use C# 9.0 feature record type with ASP.NET Core 5.0. Let's first understand a few keywords.
What is C# 9.0?
C# 9.0 is the latest version of the C# language and it is supported on .NET 5.
Features
- Records
- Init only setters
- Top-level statements
- Pattern matching enhancements
- Fit and finish features
- Support for code generators
- etc
What is ASP.NET Core?
ASP.NET Core is a cross-platform, free and open-source web framework.
What is ASP.NET Core 5.0?
ASP.NET Core is the latest version of the ASP.NET Core framework and it was released in 2020. and it Supports C# 9.0.
Features
- Model binding and validation with C# 9 record types
- Improvements to DynamicRouteValueTransformer
- OpenAPI Specification on by default
- Azure API Management Import
- Better launch experience for web API projects
- Blazor Performance improvements
- New InputFile component
- New InputRadio and InputRadioGroup components
We can transfer data back and forth from an ASP.NET Core Web API.
I have created a couple of record types to transfer data and that represents adding a new student and getting a student from the web API.
- public record StudentGetResponse
- {
- public int ID { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public DateTime EnrollmentDate { get; set; }
- }
- public record StudentAddRequest
- {
- [Required]
- public string FirstName { get; set; }
- [Required]
- public string LastName { get; set; }
- public DateTime EnrollmentDate { get; set; }
- }

Pramod ThakurPosted Aug 8, 2022, 5:30 AM
If we are setting the value of records then why can't we use class instead of record.. basic objective of the record is, that it's immutable...