CKTIS / C#
by: riferimento pratico
by: riferimento pratico: by separa un elemento dalla chiave in una clausola query group ... by.
Versione: C# language and .NET 10 reference runtime
Sintassi
by /* grammar-specific form */by separa un elemento dalla chiave in una clausola query group ... by.
Usalo nella query syntax per raggruppare secondo una chiave calcolata.
Non è una parola chiave generale fuori dal contesto query.
Chiavi null e comportamento del comparer dipendono dal provider o operatore di destinazione.
Il programma completo usa realmente by; lo stdout esatto atteso è 0:1;1:3.
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 values = new[] { 1, 2, 1, 3 };
var groups = from value in values
group value by value % 2 into parity
orderby parity.Key
select $"{parity.Key}:{parity.Count()}";
Console.WriteLine(string.Join(";", groups));
Risultato
0:1;1:3
Il programma completo usa realmente `by`; lo stdout esatto atteso è `0:1;1:3`.