Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

by: odniesienie praktyczne

by: odniesienie praktyczne: by oddziela element od klucza w klauzuli group ... by zapytania.

Wersja: C# language and .NET 10 reference runtime

Składnia

by /* grammar-specific form */

by oddziela element od klucza w klauzuli group ... by zapytania.

Stosuj w query syntax do grupowania według wyliczonego klucza.

Nie jest ogólnym słowem kluczowym poza kontekstem zapytania.

Null keys i comparer zależą od docelowego providera/operatora.

Kompletny program rzeczywiście używa by; oczekiwany stdout to dokładnie 0:1;1:3.

Przykłady

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));

Wynik

0:1;1:3

Kompletny program rzeczywiście używa `by`; oczekiwany stdout to dokładnie `0:1;1:3`.

Źródła