Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a list distinct list of a list

Tags:

c#

list

I have a C# List of sting which can be x rows long. a small example will be shown below. I would like to know how i would to now how i can get small distinct list so that A doesn't appear multiple time. this list is coming for code. so it random.

list = {a,b,a,f,a,null,a,e,a,e}
like image 489
Simon Patel Avatar asked Dec 05 '25 11:12

Simon Patel


1 Answers

Try LINQ .... To be more specific... Given that your list is actually string[] you could do this...

string[] list = {"a","b","a","f","a",null,"a","e","a","e"};
var distinctList = list.Distinct();

foreach (var str in distinctList)//Distinct list of values
{
    Console.Write(str); 
}
like image 54
Mortalus Avatar answered Dec 07 '25 00:12

Mortalus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!