using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DistinctTest(new int[] { 1, 1, 2, 2, 2, 3, 3, 3, 1, 2, 3, 4 }); DistinctTest(new int[] { 1, 1, 1 }); } private static void DistinctTest(int[] testArray) { Console.Write("Before : "); foreach (int value in testArray) { Console.Write(value.ToString() + ", "); } Console.Write(Environment.NewLine + "After : "); foreach (int value in GetDistinctValues(testArray)) { Console.Write(value.ToString() + ", "); } Console.WriteLine(Environment.NewLine); } static public T[] GetDistinctValues(T[] array) { List tmp = new List(); for (int i = 0; i < array.Length; i++) { if (tmp.Contains(array[i])) continue; tmp.Add(array[i]); } return tmp.ToArray(); } } }