Skip to content

Commit

Permalink
chore: Adjust explanation for immutable records
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed Mar 6, 2024
1 parent f38fbfb commit 24d414e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/Learn/Mvux/WorkingWithRecords.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 24d414e

Please sign in to comment.