How to create comma delimited string from a specific list of values ​​using LINQ?

I have a list of values:

myCars

with values:

Ford
Ford
VW
Renault
Jeep
Jeep

referenced via:

myCars.Makers

I want to create a different comma delimited string to get:

Ford,VW,Renault,Jeep

I assume that I need to run a separate sentence on myCars, but I'm not sure how to convert the comma delimited string as above.

Thank you very much in advance

+4
source share
1 answer

use string.JoinandDistinct

string.Join(",", myCars.Makers.Distinct());
+13
source

Source: https://habr.com/ru/post/1529233/


All Articles