From 24d414e0d3070fd07aa95e79cfd09fc033dbea66 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Wed, 6 Mar 2024 12:01:32 +0000 Subject: [PATCH] chore: Adjust explanation for immutable records --- doc/Learn/Mvux/WorkingWithRecords.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/Learn/Mvux/WorkingWithRecords.md b/doc/Learn/Mvux/WorkingWithRecords.md index eee5522522..191e684c67 100644 --- a/doc/Learn/Mvux/WorkingWithRecords.md +++ b/doc/Learn/Mvux/WorkingWithRecords.md @@ -12,7 +12,9 @@ A [record](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/bu public record MyRecord(); ``` -Records **can** be, but are not necessarily, immutable. Also, records introduce the `with` operator, which is a helpful tool to deal with immutable objects, we will see more about this operator in the **Updating records** section. +Records **can** be, but are not necessarily, immutable. When creating a record, it's important to use the keyword `init` instead of `set` for properties. If you choose `set`, the record won't remain immutable. Consequently, you won't be able to prevent values from changing once they're set. Additionally, ensure that sub properties or objects also remain immutable to maintain the integrity of the entire structure. + +Also, records introduce the `with` operator, which is a helpful tool to deal with immutable objects, we will see more about this operator in the **Updating records** section. > [!IMPORTANT] > \* When using `record struct`, there are some differences in how it behaves compared to regular records or classes because it combines value-type characteristics with the features of records. Learn more about [`struct`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct). @@ -60,8 +62,6 @@ public partial record ChatResponse(string Message) new ChatResponse("Hello, I'm a bot"); //with IsError defaulting to false ``` -When you create a record, if you let the properties change with the `set` keyword, the record won't be immutable. This means you won't be able to lock in or keep the values from changing once you've set them. - ## How to use records with MVUX Records are designed to be a simple data structure, excellent for exchanging data, such as requests and responses, between application layers.