Immutable object: Difference between revisions

Content deleted Content added
Tag: Reverted
Line 76:
By enforcing all the fields as immutable, you obtain an immutable type.
 
<syntaxhighlight lang="CSharpcsharp">
class AnImmutableType
{
Line 89:
}
}
</syntaxhighlight>
 
C# have records which are immutable.<ref>{{cite web |title=Use record types - C# tutorial - C# |url=https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/records |website=learn.microsoft.com |access-date=23 February 2024 |language=en-us |date=14 November 2023}}</ref><ref>{{cite web |title=Records - C# reference - C# |url=https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record |website=learn.microsoft.com |access-date=23 February 2024 |language=en-us |date=25 May 2023}}</ref>
<syntaxhighlight lang="csharp">
record Person(string FirstName, string LastName);
</syntaxhighlight>