CKTIS / C#
record: praktische referentie
record: praktische referentie: record genereert waardegelijkheid, afdruk en ondersteuning voor with; alleen een positionele record synthetiseert automatisch Deconstruct.
Versie: C# language; verified against C# 14 reference
Syntax
record /* grammar-specific form */record genereert waardegelijkheid, afdruk en ondersteuning voor with; alleen een positionele record synthetiseert automatisch Deconstruct.
Gebruik dit voor gegevensmodellen waarvan de identiteit uit componenten volgt.
Onveranderlijkheid is oppervlakkig; een mutable member kan de zichtbare toestand nog wijzigen.
record class heeft referentieaard en record struct waardeaard; gelijkheid omvat het runtime type.
Het volledige programma gebruikt record werkelijk; de exact verwachte stdout is Ada.
Voorbeelden
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var person = new Person("Ada"); Console.WriteLine(person.Name);
sealed record Person(string Name);
Resultaat
Ada
Het volledige programma gebruikt `record` werkelijk; de exact verwachte stdout is `Ada`.