Lambda CrossJoin

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            List<MD_Item> itemList = new List<MD_Item>();
            itemList.Add(new MD_Item { ItemCode = "A9000124", ItemDesc = "笔记本电脑" });
            itemList.Add(new MD_Item { ItemCode = "A9000125", ItemDesc = "机械键盘" });


            List<MD_Warehouse> whsList = new List<MD_Warehouse>();
            whsList.Add(new MD_Warehouse { WhsCode = "YL", WhsDesc = "原料仓" });
            whsList.Add(new MD_Warehouse { WhsCode = "CP", WhsDesc = "成品仓" });


            var crossJoinLambda = itemList.SelectMany(t1 => whsList.Select(t2 => new WM_Stock
            {
                ItemCode = t1.ItemCode,
                ItemDesc = t1.ItemDesc,
                WhsCode = t2.WhsCode,
                WhsDesc = t2.WhsDesc
            })).ToList();


            Console.ReadKey();

        }
    }

    public class MD_Item
    {
        public string ItemCode { get; set; }

        public string ItemDesc { get; set; }
    }


    public class MD_Warehouse
    {
        public string WhsCode { get; set; }

        public string WhsDesc { get; set; }
    }


    public class WM_Stock
    {
        public string ItemCode { get; set; }

        public string ItemDesc { get; set; }

        public string WhsCode { get; set; }

        public string WhsDesc { get; set; }

    }

}

  

上一篇:Java核心卷一之接口、lambda 表达式与内部类


下一篇:Jdk1.8新特性