■ join 키워드 질의 형식을 사용하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
using System; using System.Linq; /// <summary> /// 제품 /// </summary> public class Product { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 제품 코드 /// </summary> public string ProductCode; /// <summary> /// 제품명 /// </summary> public string ProductName; #endregion } /// <summary> /// 제품 재고 /// </summary> public class ProductStock { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 제품 코드 /// </summary> public string ProductCode; /// <summary> /// 수량 /// </summary> public int Quantity; #endregion } ... var resultEnumerable = from product in productArray join productStock in productStockArray on product.ProductCode equals productStock.ProductCode where productStock.ProductCode == "C001" select new { ProductName = product.ProductName, Quantity = productStock.Quantity }; foreach(var result in resultEnumerable) { Console.WriteLine(result.ProductName + ", " + result.Quantity.ToString()); } |