Repository navigation
DE CSharp Keyword by
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Handbuch C# · Praktischer Leitfaden
Trennt den Elementwert vom Schlüssel in der Gruppe ... durch ... .
Speichern Sie dieses Beispiel separat als Example.cs. Führen Sie es unabhängig von den anderen Beispielen dieser Seite aus.
Example.cs:
// PROJECT-EXAMPLE
using System.Linq;
int[] values = [1, 2, 3];
var result = from n in values group n by n % 2 into groups select groups.Key;
System.Console.WriteLine(string.Join(",", result));Ergebnis:
1,0
group value by keyDie Abfrage wird während des Durchlaufs normalerweise verzögert ausgeführt. ToArray/ToList erfasst das Ergebnis in einer neuen Sammlung.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
int[] values = [1, 2, 3, 4, 5];
var query = from value in values
let parity = value % 2
group value by parity into grouped
where grouped.Any()
orderby grouped.Key ascending
select new { Key = grouped.Key, Total = grouped.Sum() };
foreach (var item in query) Console.WriteLine($"{item.Key}:{item.Total}");
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
string[] names = ["ore", "oak", "wood"];
var query = from name in names
group name by name[0] into grouped
orderby grouped.Key descending
select new { Letter = grouped.Key, Names = string.Join(",", grouped) };
foreach (var item in query) Console.WriteLine($"{item.Letter}:{item.Names}");
}
}Offizielle Quelle: Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE