Remove duplicates from array

Total Post:341


 1883  View(s)
Rate this:

Hi Everyone!

I have been working with a string[] array in C# that gets returned from a function call. I was wondering what the best way to remove duplicates from this

array would be? I could possibly cast to a Generic collection, but I was wondering if there was a better way to do it, possibly by using a temp array?

Thanks in advance!

  1. Re: Remove duplicates from array

    Hi Ankit,

    You can remove Duplicates by using a HashSet.

    string[] names = {"Windows", "Oracle", "Windows", "Csharp", "Oracle", "Windows", "Telnet", "Oracle", "Csharp" };
                var AlteredSet = new HashSet<string>(names);
                foreach (string str in AlteredSet)


      Modified On Mar-29-2018 10:54:10 PM
  1. Re: Remove duplicates from array

    Hi Ankit!

    You could try this way!

    int[] nAs = { 1, 2, 3, 3, 4}; 
    int[] nQ = nAs.Distinct().ToArray();

      Modified On Feb-18-2013 01:33:19 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.