2009-05-16 25 views

Antwort

1

Mit LINQ bekommen kann Ihr Problem leicht lösen:

class Program 
{ 
    static string[] ar = new[] { "a", "b", "c", "d", "a", "a", "f", "g", 
     "d", "i", "j", "a","d", "c", "g" }; 

    static void Main(string[] args) 
    { 
     var dist = (from a in ar select a).Distinct();// distinct; 
     foreach (var v in dist) 
      Console.Write(v); 
     Console.ReadLine(); 
    } 
} 

Es erzeugt diese Ausgabe:

abcdfgij 
0
GenericList.Distinct() 
4
using System.Linq; 
class Program 
{ 
    static void Main() 
    { 
     var array = new int[] { 1, 2, 2, 3 }; 
     var distinctArray = array.Distinct().ToArray(); 
    } 
} 
Verwandte Themen