if you consider STL methods to be "very efficient", so use the following:
var vals = new List<int> { 1, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 2, 3 }; vals.Sort(); var uniques = new HashSet<int>(vals);
For equivalent 2.0
List<int> vals = new List<int>(); vals.Add(1); vals.Add(2); vals.Add(3); vals.Add(2); ... vals.Sort(); List<int> uniques = new List<int>(); vals.ForEach(delegate(int v) { if (!uniques.Contains(v)) uniques.Add(v); });
Tamir source share