Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

records and aggregates: praktická referencia

records and aggregates: praktická referencia: Agregáty zoskupujú zložky do jednej hodnoty; tuple a pozičné recordy podporujú deconstruction, kým nepozičný record Deconstruct automaticky nesyntetizuje.

Verzia: C# language and .NET 10 reference runtime

Syntax

// records aggregates

Agregáty zoskupujú zložky do jednej hodnoty; tuple a pozičné recordy podporujú deconstruction, kým nepozičný record Deconstruct automaticky nesyntetizuje.

Použite na výslovné viacpoľové výsledky namiesto voľných parametrov.

Veľké meniteľné agregáty sťažujú udržanie invariantu.

Default môže obsahovať nuly alebo null a deconstruction musí zachovať význam poradia.

Úplný program skutočne používa records and aggregates; presne očakávaný stdout je 5.

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 point = new Point(2, 3); var (x, y) = point; Console.WriteLine(x + y); readonly record struct Point(int X, int Y);

Výsledok

5

Úplný program skutočne používa `records and aggregates`; presne očakávaný stdout je `5`.

Zdroje