Remove duplicates in the string array using LINQ in C#

Home Forums General Programming C# Remove duplicates in the string array using LINQ in C#

This topic contains 0 replies, has 2 voices, and was last updated by  Hirendra Sisodiya 4 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4612

    Shalabh
    Participant

    In my application i have written a function that create the array of the codes from database. Just like that:

    [code title=””]
    codes[0] = “ERQ”
    codes[0] = “RTQ”
    codes[0] = “POQ”
    codes[0] = “ERQ”
    codes[0] = “POQ”
    codes[0] = “TRQ”
    [/code]

    After that i need all values but in one case i need only distinct values.
    This time i am creating the HashSet object to remove the duplicates values. Can i use the LINQ, of yes than what will be the linq query to remove duplicates?

    #4615

    just use the:

    [code title=”C#”]int[] q = s.Distinct().ToArray();[/code]

    You can also use the LIST object to remove the duplicates:

    http://msdn.microsoft.com/en-us/library/bb348436.aspx

    thanks

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.