CKTIS / C#
records and aggregates: praktická reference
records and aggregates: praktická reference: Agregáty seskupují složky do jedné hodnoty; tuple a poziční recordy podporují deconstruction, zatímco nepoziční record Deconstruct automaticky nesyntetizuje.
Verze: C# language and .NET 10 reference runtime
Syntaxe
// records aggregatesAgregáty seskupují složky do jedné hodnoty; tuple a poziční recordy podporují deconstruction, zatímco nepoziční record Deconstruct automaticky nesyntetizuje.
Použijte pro výslovné vícepolové výsledky místo volných parametrů.
Velké měnitelné agregáty ztěžují udržení invariantu.
Default může obsahovat nuly nebo null a deconstruction musí zachovat význam pořadí.
Úplný program skutečně používá records and aggregates; přesně očekávaný stdout je 5.
Pří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 point = new Point(2, 3); var (x, y) = point; Console.WriteLine(x + y); readonly record struct Point(int X, int Y);
Výsledek
5
Úplný program skutečně používá `records and aggregates`; přesně očekávaný stdout je `5`.