How to remove a duplicates values from the array and list

Hello I have to remove the Duplicate values from the array Or list how to do that
I have {“value1”,“value2”,“value1”,“value4”}
How to remove duplicates values from it

USE LINQ or some other way you know please give me a solution

I use this one From s in ListOf_String Select s distinct

But I couldn’t Understand what is this can anyone explain

Thanks
Chethan P

1 Like

Hi,

How about the following expression?

arrString.Where(Function(x) arrString.Count(function(y) y=x)=1).ToArray

Regards,

1 Like

What about Union we can use this? instead of where
How to use this Union

If you don’t mind can you please explain this

regards

Hi,

What about Union we can use this? instead of where

Union method produces the set union of two sequences. I don’t think it’s suitable for this case.

arrString.Count(function(y) y=x)=1)

This means, if number of the items (each item) is 1, it returns true, if not 1 returns false. As a result, we can filter duplicated items using Where method.

Regards,

2 Likes

Hi,
Sorry. I might have misunderstanding.

If your expected result is {“value1”,“value2”,“value4”} ,the following Union method works.

arrString.Union(arrString).ToArray

The above expression :

arrString.Where(Function(x) arrString.Count(function(y) y=x)=1).ToArray

returns {“value2”,“value4”}

Regards,

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.