CKTIS / C#
records and aggregates: referencia práctica
records and aggregates: referencia práctica: Los agregados agrupan componentes en un valor; las tuplas y los records posicionales admiten deconstruction, mientras un record no posicional no sintetiza Deconstruct automáticamente.
Versión: C# language and .NET 10 reference runtime
Sintaxis
// records aggregatesLos agregados agrupan componentes en un valor; las tuplas y los records posicionales admiten deconstruction, mientras un record no posicional no sintetiza Deconstruct automáticamente.
Úsalos para resultados explícitos de varios campos en vez de parámetros sueltos.
Los agregados mutables grandes dificultan mantener un invariante.
Default puede contener ceros o null y deconstruction debe preservar el significado del orden.
El programa completo usa realmente records and aggregates; su stdout esperado exacto es 5.
Ejemplos
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);
Resultado
5
El programa completo usa realmente `records and aggregates`; su stdout esperado exacto es `5`.