CKTIS / C#
by: praktična referenca
by: praktična referenca: by loči element od ključa v klavzuli query group ... by.
Različica: C# language and .NET 10 reference runtime
Sintaksa
by /* grammar-specific form */by loči element od ključa v klavzuli query group ... by.
Uporabite v query syntax za združevanje po izračunanem ključu.
Zunaj konteksta poizvedbe ni splošna ključna beseda.
null ključi in vedenje comparer so odvisni od ciljnega providerja ali operatorja.
Celoten program dejansko uporabi by; natančno pričakovani stdout je 0:1;1:3.
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 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));
Rezultat
0:1;1:3
Celoten program dejansko uporabi `by`; natančno pričakovani stdout je `0:1;1:3`.