C#のMailAddressに複数の文字列を追加しようとしています。
を使用するForEach
と、コードは次のようになります。
foreach (var item in GetPeopleList())
{
m.Bcc.Add(new MailAddress(item.EmailAddress));
}
私は今、foreach(つまりList.ForEach()
)でこれを実行しようとしていますが、できません。
public class Person
{
public Person(string firstName, string lastName, string emailAddress)
{
FirstName = firstName;
LastName = lastName;
EmailAddress = emailAddress;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
}
static void Main(string[] args)
{
MailMessage m = new MailMessage();
List<Person> people = GetPeopleList();
m.Bcc.Add(people.ForEach(Person people =>
{
//what goes here?
}
));
}
private static List<Person> GetPeopleList()
{
List<Person> peopleList = new List<Person>();
//add each person, of type Person, to the list and instantiate the class (with the use of 'new')
peopleList.Add(new Person("Joe", "Bloggs", "Joe.Bloggs@foo.bar"));
peopleList.Add(new Person("John", "Smith", "John.Smith@foo.bar"));
peopleList.Add(new Person("Ann", "Other", "Ann.Other@foo.bar"));
return peopleList;
}
私はこれのいくつかのバージョン/バリエーションを試しましたが、明らかに何か間違ったことをしています。私はそれについてのエリック・リッパートのページを読みました、そして悲しいことにこれも助けにはなりませんでした。