Repository navigation
KO CSharp Keyword ascending
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
orderby 키의 오름차순 방향을 지정합니다. 이는 기본 방향이지만 명시적으로 작성할 수 있습니다.
이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.
Example.cs:
// PROJECT-EXAMPLE
using System.Linq;
int[] values = [1, 2, 3];
var result = from n in values orderby n ascending select n;
System.Console.WriteLine(string.Join(",", result));결과:
1,2,3
orderby key ascending쿼리는 일반적으로 순회 중에 지연된 방식으로 실행됩니다. ToArray/ToList는 새 컬렉션에 결과를 캡처합니다.
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)
{
var items = new[] { new { Id = 1, Name = "ore" }, new { Id = 2, Name = "wood" } };
var counts = new[] { new { Id = 1, Count = 4 }, new { Id = 2, Count = 2 } };
var query = from item in items
join count in counts on item.Id equals count.Id
let total = count.Count * 2
where total > 3
orderby total descending, item.Name ascending
select new { item.Name, Total = total };
foreach (var item in query) Console.WriteLine($"{item.Name}:{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)
{
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}");
}
}공식 출처: Microsoft 학습.
ClassicUO — Bad Newbie & C# Scripts IDE