CKTIS / C#
reductions and statistics: praktická reference
reductions and statistics: praktická reference: Redukce skládá posloupnost do statistiky, například součtu, průměru, minima nebo histogramu.
Verze: C# language and .NET 10 reference runtime
Syntaxe
// reductions statisticsRedukce skládá posloupnost do statistiky, například součtu, průměru, minima nebo histogramu.
Zvolte typ akumulátoru a numericky stabilní algoritmus podle měřítka dat.
Průměr ze součtu může přetéct a floating point kumuluje chybu.
Prázdná data, null, NaN a jedno pozorování vyžadují výslovnou definici výsledku.
Úplný program skutečně používá reductions and statistics; přesně očekávaný stdout je sum=12,avg=4.
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 values = new[] { 2, 4, 6 }; Console.WriteLine($"sum={values.Sum()},avg={values.Average()}");
Výsledek
sum=12,avg=4
Úplný program skutečně používá `reductions and statistics`; přesně očekávaný stdout je `sum=12,avg=4`.