As I know record type can be immutable(cannot be changed once object is created) reference type.
So what are different prectical scenarios where record type uses is more relevant and appropriate instead of Class?
As I know record type can be immutable(cannot be changed once object is created) reference type.
So what are different prectical scenarios where record type uses is more relevant and appropriate instead of Class?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aravind GovindarajRank #430 · 5.8K reputationPosted Jan 12, 2023, 11:00 AM EST
Hi, Please refer to this link it clears your queries
https://josipmisko.com/posts/c-sharp-class-vs-record
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jan 12, 2023, 11:44 AM EST
If main purpose of storing data then use record types, if responsibility need to define then use class
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Jan 12, 2023, 1:44 PM EST
In a simple way, a class is an OOP concept that wraps data with functionality, while a record represents a set of data.
Records should not have any state changes after instantiation (immutable state), while classes change properties.
Use a record when an object's only purpose is to contain public data. On other hand, use a class if your object has unique logic. Classes are mutable so even if they have the same data, doesn't mean they are the same.
Munib ButtRank #156 · 14.9K reputationPosted Jan 12, 2023, 3:30 PM EST
Use Records in C# when you want to compare instances using values of the properties.
Saravanan GanesanRank #153 · 15.1K reputationPosted Sep 25, 2023, 1:43 PM EDT
Record types are ideal for representing immutable data with value semantics, such as entities with no identity change, like date/time objects, configurations, or DTOs. They simplify code, enhance readability, and reduce the chance of bugs in scenarios where data changes should not occur, making them more appropriate than classes for such cases.