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