Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / C#

reductions and statistics: referência prática

reductions and statistics: referência prática: Uma redução agrega uma sequência numa estatística como soma, média, mínimo ou histograma.

Versão: C# language and .NET 10 reference runtime

Sintaxe

// reductions statistics

Uma redução agrega uma sequência numa estatística como soma, média, mínimo ou histograma.

Escolhe um tipo acumulador e um algoritmo numericamente estável para a escala dos dados.

Uma média calculada pela soma pode exceder e floating point acumula erro.

Dados vazios, null, NaN e uma observação exigem definição explícita do resultado.

O programa completo usa realmente reductions and statistics; o stdout exato esperado é sum=12,avg=4.

Exemplos

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()}");

Resultado

sum=12,avg=4

O programa completo usa realmente `reductions and statistics`; o stdout exato esperado é `sum=12,avg=4`.

Fontes