Reputation: 8966
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
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