简体   繁体   中英

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

I have a list of values:

myCars

with values:

Ford
Ford
VW
Renault
Jeep
Jeep

which is referenced via:

myCars.Makers

I wish to create a distinct comma delimited string from this such that I get:

Ford,VW,Renault,Jeep

I am guessing that I need to run a distinct clause on myCars, but then am unsure about how to convert to comma delimited string as above.

Many thanks in advance

使用string.JoinDistinct

string.Join(",", myCars.Makers.Distinct());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM