Linq之左聯接

hhw199112發表於2018-06-21
            int[] arr1 = { 32, 3, 432, 543, 23, 5, 634 };
            int[] arr2 = { 64, 4, 8, 3, 3, 6, 23, 5, 2 };
            var query = from val in arr1 join val2 in arr2 on val equals val2 into temp
                        from grp in temp.DefaultIfEmpty()
                        select new { val, grp };
            //DefaultIfEmpty(),匹配不上,會給個預設值,這裡給0
            foreach (var item in query)
            {
                Console.WriteLine(item);
               
            }

相關文章