tags:

views:

88

answers:

2

In C# 3.0 for ,Removiing duplicates I can use

       int[] ints={1,1,2,34,5,6,7,5,11,13};
       List<int> integes = new List<int>();
       List<int> filter = new List<int>();
       integes.AddRange(ints);
       filter = integes.Distinct().ToList();
       filter.ForEach((i)=> { Console.WriteLine(i); });

Is similar shortcut method is available in ASP.NET 2.0 .

A: 

Loop .Adds intead of an .AddRange and check for integes.Contains(int) in the loop.

tsilb
+1  A: 

Do you mean something like this?

integes.ForEach(delegate(int i) {if(!filter.Contains(i)) {filter.Add(i);}});
Konamiman
yes this is the one.
So, why is `for (...) { ... }` evil and `list.ForEach(...)` good?
Heinzi
Then do I deserve the answer to be accepted? :-)
Konamiman
why not ? I marked it as accepted. :) :)
Thanks! (Lorem ipsum and 15 characters needed)
Konamiman
Note that this solution is O(n^2) if there are no duplicates. If the list is small or contains lots of duplicates it will be reasonably fast, but its time performance will inevitably be terrible if the list is large and duplicates are few. If you're in that situation, consider using a hash table to check for duplicates; hash tables are highly optimized for duplicate detection.
Eric Lippert