8. 集合操作符—【LINQ标准查询操作符】
public class Distinct_LINQ { public static void Distinct_Print() { List<int> quantity = new List<int> { 1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10 }; IEnumerable<int> val = quantity.Distinct(); foreach (int i in val) { Console.WriteLine(i.ToString()); } } public static void Union_Print() { int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] numbers2 = { 11, 12, 13, 14, 15, 16, 17, 18 }; IEnumerable<int> union = numbers1.Union(numbers2); foreach (int i in union) { Console.WriteLine(i.ToString()); } } public static void Intersect_Print() { int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] numbers2 = { 1, 2, 13, 14, 5, 16, 7, 18 }; IEnumerable<int> intersect = numbers1.Intersect(numbers2); foreach (int i in intersect) { Console.WriteLine(i.ToString()); } } public static void Except_Print() { int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] numbers2 = { 1, 2, 13, 14, 5, 16, 7, 18 }; IEnumerable<int> except = numbers1.Except(numbers2); foreach (int i in except) { Console.WriteLine(i.ToString()); } } }
【天天来(http://www.daydaycome.com)】- 精选折扣商品,爆料精选,九块九白菜底价尽在天天来!是一个中立的,致力于帮助广大网友买到更有性价比网购产品的分享平台,每天为网友们提供最受追捧 最具性价比 最大幅降价潮流新品资讯。我们的信息大部分来自于网友爆料,如果您发现了优质的产品或好的价格,不妨给我们爆料(谢绝商家)