CKTIS / C#
records and aggregates: praktična referenca
records and aggregates: praktična referenca: Agregati združijo komponente v eno vrednost; tuple in pozicijski recordi podpirajo deconstruction, nepozicijski record pa Deconstruct ne sintetizira samodejno.
Različica: C# language and .NET 10 reference runtime
Sintaksa
// records aggregatesAgregati združijo komponente v eno vrednost; tuple in pozicijski recordi podpirajo deconstruction, nepozicijski record pa Deconstruct ne sintetizira samodejno.
Uporabite za izrecne večpoljne rezultate namesto ohlapnih parametrov.
Veliki spremenljivi agregati otežijo ohranjanje invarianta.
Default lahko vsebuje ničle ali null, deconstruction pa mora ohraniti pomen vrstnega reda.
Celoten program dejansko uporabi records and aggregates; natančno pričakovani stdout je 5.
Primeri
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);
Rezultat
5
Celoten program dejansko uporabi `records and aggregates`; natančno pričakovani stdout je `5`.