Reputation: 4124
I would like to join multiple strings in my format:
Like: string1:string2,string1:string2, and more...
I have list with string1 and string2 values.
string test = String.Join(",", mylist.Select(x => x.string1));
How can I join these variables in my format ?
Upvotes: 1
Views: 779
Reputation: 5405
Assuming:
string1
and string2
are properties from a custom objectmylist
is a generic list of this custom objectYou could just change your Select
like this:
string.Join(",", mylist.Select(x => string.Format("{0}:{1}", x.string1, x.string2));
Upvotes: 5
Reputation: 2289
This should do it for you
string result = string.Join(",", myList.Select(x=> string.Join(":", x.string1, x.string2)));
Upvotes: 2