ICollection<MailAddress> toCollection = to.Split(',');
此操作失败,因为字符串不会自动MailAddress
...
如何迭代字符串,将每个实例设为MailAddress
,然后将其添加到新的ICollection
?
答案 0 :(得分:2)
你可以做到
using System.Linq;
....
IEnumerable<MailAddress> addresses = to.Split(',').Select(i => new MailAddress(i));
编辑:将其设为ICollection<MailAddress>
ICollection<MailAddress> collection = to.Split(',').Select(i => new MailAddress(i)).[ToList | ToArray]();