从列表中打印唯一值的 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 红包祝福语简短10字
18 周六早晨祝福语简短