KO CSharp Keyword into - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: into
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๊ทธ๋ฃน/์ ํ ํ ์ฟผ๋ฆฌ๋ฅผ ๊ณ์ํ๊ฑฐ๋ ๊ทธ๋ฃน ์กฐ์ธ ๊ฒฐ๊ณผ๋ฅผ ํธ์ถํฉ๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
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.Count();
System.Console.WriteLine(string.Join(",", result));
๊ฒฐ๊ณผ:
2,1
ํต์ฌ๋ก
group value by key into groupName ...
์ฟผ๋ฆฌ๋ ์ผ๋ฐ์ ์ผ๋ก ์ํ ์ค์ ์ง์ฐ๋ ๋ฐฉ์์ผ๋ก ์คํ๋ฉ๋๋ค. ToArray/ToList๋ ์ ์ปฌ๋ ์ ์ ๊ฒฐ๊ณผ๋ฅผ ์บก์ฒํฉ๋๋ค.
์์ 1: ๊ธฐ๋ณธ ํํ
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}");
}
}
์ 2: ๋ ๋ค๋ฅธ ์ค์ ํ์
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}");
}
}
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.