KO CSharp Keyword from - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: from
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
LINQ ์ฟผ๋ฆฌ๋ฅผ ์์ํ๊ฑฐ๋ ์ค์ฒฉ๋ ์ํ์ค ํ์์ ์ถ๊ฐํฉ๋๋ค. ๋ฒ์ ๋ณ์ ์ด๋ฆ์ ๋ค์ ์ ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
using System.Linq;
int[] values = [1, 2, 3];
var result = from n in values select n;
System.Console.WriteLine(string.Join(",", result));
๊ฒฐ๊ณผ:
1,2,3
ํต์ฌ๋ก
from item in items ...
์ฟผ๋ฆฌ๋ ์ผ๋ฐ์ ์ผ๋ก ์ํ ์ค์ ์ง์ฐ๋ ๋ฐฉ์์ผ๋ก ์คํ๋ฉ๋๋ค. 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)
{
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}");
}
}
์ 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)
{
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 ํ์ต.