避免重复数组

时间:2010-02-15 08:40:10

标签: asp.net

  

可能重复:
  Avoid duplicates

你好,  我想避免数组中的重复条目.....(在c#中)

2 个答案:

答案 0 :(得分:1)

使用不同的方法:

public static void DistinctExample()
{
    string[] names = new string[] { "Peter", "Paul", "Mary", 
        "Peter", "Paul", "Mary", "Janet" };

    var q = (from s in names
            select s).Distinct();

    foreach (var name in q) {
        Console.WriteLine(name);
    }

    Console.ReadLine();
}

答案 1 :(得分:0)