KO CSharp Keyword join - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: join

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

๋‘ ์‹œํ€€์Šค๋ฅผ ๋™์ผํ•œ ํ‚ค๋กœ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค. Join ... into๋Š” ๊ทธ๋ฃน ์กฐ์ธ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
using System.Linq;
int[] values = [1, 2, 3];
var result = from n in values join other in new[] { 2 } on n equals other select n;
System.Console.WriteLine(string.Join(",", result));

๊ฒฐ๊ณผ:

2

ํ†ต์‚ฌ๋ก 

join right in values on left.Key equals right.Key

์ฟผ๋ฆฌ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์ˆœํšŒ ์ค‘์— ์ง€์—ฐ๋œ ๋ฐฉ์‹์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. 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)
    {
        var owners = new[] { new { Id = 1, Name = "A" }, new { Id = 2, Name = "B" } };
        var items = new[] { new { OwnerId = 1, Name = "ore" } };
        var query = from owner in owners
                    join item in items on owner.Id equals item.OwnerId into owned
                    from item in owned.DefaultIfEmpty()
                    select $"{owner.Name}:{item?.Name ?? "empty"}";
        foreach (string text in query) Console.WriteLine(text);
    }
}

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.