从列表中打印唯一值的 C# 程序
设置列表。
List < int > list = new List < int > (); list.Add(99); list.Add(49); list.Add(32);
获得独特的元素。
ListmyList = list.Distinct().ToList();
这是显示列表中唯一值的完整示例。
示例
using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
public static void Main() {
List < int > list = new List < int > ();
list.Add(55);
list.Add(45);
list.Add(55);
list.Add(65);
list.Add(73);
list.Add(24);
list.Add(65);
Console.WriteLine("初始名单...");
foreach(int a in list) {
Console.WriteLine("{0}", a);
}
List < int > myList = list.Distinct().ToList();
Console.WriteLine("独特的元素...");
foreach(int a in myList) {
Console.WriteLine("{0}", a);
}
}
}输出结果初始名单... 55 45 55 65 73 24 65 独特的元素... 55 45 65 73 24
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语