简单一维集合的使用

//实例2个集合
List < int > ages = new List < int >{21, 46, 46, 55, 17, 21, 55, 55}; List < string > names = new List < string >{"wang", "li", "zhang", "li", "wang", "chen", "he", "wang"};
IEnumerable
< int > distinctAges = ages.Distinct(); Console.WriteLine("Distinct ages:"); foreach(int age in distinctAges) { Console.WriteLine(age); } var distinctNames = names.Distinct(); Console.WriteLine("\nDistinct names:");
foreach(string name in distinctNames) { Console.WriteLine(name); }
List
< int > ages = new List < int >{21, 46, 46, 55, 17, 21, 55, 55}; List < int > disAge = ages.Distinct().ToList(); //除重 foreach(int a in disAge) Console.WriteLine(a);

相关文章:

  • 2021-09-14
  • 2021-12-09
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案