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 ํ•™์Šต.