vilmarci
vilmarci

Reputation: 531

Join string properties of list of objects

I've got list of Contact objects that among others, has a mailaddress string property. I would like to create a ";" delimited string from all these addresses. Is it possible to do this with a built-in function like the Join(delimiter,array) or the Join (of ...), without iterating trough the list manually?

Upvotes: 1

Views: 3288

Answers (2)

jmoreno
jmoreno

Reputation: 13571

Sorta.

Dim str = string.Join(";"c, YourList.Select(function(c) c.mailaddress))

You don't have to use a foreach loop, but the list does have to be iterated. LINQ can do that for you.

Upvotes: 9

Mike
Mike

Reputation: 442

Short answer, NO.

You will have to iterate through all the Contacts, adding the mailaddress properties to a New List(Of String).

To get your delimited string, YourList.ToArray().Join(",")

Hope that helps.

Upvotes: -1

Related Questions