JacobIRR
JacobIRR

Reputation: 8966

convert list of strings to ICollection of MailAddresses

ICollection<MailAddress> toCollection = to.Split(',');

This fails because strings aren't automatically MailAddress...

How can you iterate over the strings, make each instance a MailAddress and then add those to a new ICollection?

Upvotes: 0

Views: 1515

Answers (1)

dcg
dcg

Reputation: 4219

You can do

using System.Linq;
....
IEnumerable<MailAddress> addresses = to.Split(',').Select(i => new MailAddress(i));

EDIT: Making it an ICollection<MailAddress>

ICollection<MailAddress> collection = to.Split(',').Select(i => new MailAddress(i)).[ToList | ToArray]()];

Upvotes: 3

Related Questions