CKTIS / C#
record: praktická referencia
record: praktická referencia: record generuje hodnotovú rovnosť, výpis a podporu with; Deconstruct automaticky syntetizuje iba pozičný record.
Verzia: C# language; verified against C# 14 reference
Syntax
record /* grammar-specific form */record generuje hodnotovú rovnosť, výpis a podporu with; Deconstruct automaticky syntetizuje iba pozičný record.
Použite pre dátové modely, ktorých identita plynie zo zložiek.
Nemennosť je plytká; mutable member môže stále zmeniť pozorovateľný stav.
record class má referenčnú a record struct hodnotovú povahu; rovnosť zahŕňa runtime type.
Úplný program skutočne používa record; presne očakávaný stdout je Ada.
Príklady
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);
Výsledok
Ada
Úplný program skutočne používa `record`; presne očakávaný stdout je `Ada`.