CKTIS / C#
records and aggregates: riferimento pratico
records and aggregates: riferimento pratico: Gli aggregati raggruppano componenti in un valore; tuple e record posizionali supportano la deconstruction, mentre un record non posizionale non sintetizza automaticamente Deconstruct.
Versione: C# language and .NET 10 reference runtime
Sintassi
// records aggregatesGli aggregati raggruppano componenti in un valore; tuple e record posizionali supportano la deconstruction, mentre un record non posizionale non sintetizza automaticamente Deconstruct.
Usali per risultati espliciti a più campi invece di parametri sciolti.
Aggregati modificabili grandi rendono difficile mantenere un invariante.
Default può contenere zeri o null e deconstruction deve preservare il significato dell’ordine.
Il programma completo usa realmente records and aggregates; lo stdout esatto atteso è 5.
Esempi
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);
Risultato
5
Il programma completo usa realmente `records and aggregates`; lo stdout esatto atteso è `5`.