I have an class called message, inside which I have a IEnumerable called copies.
I need to create a new Recipient class object with the copies content.
In order to do that, I created a Recipient list, then interacting on copies using ForEach method; But I took so much code lines, and it doesn't feel good for me. There is a way to do that using LINQ methods?
I'll put below what I've done so far.
CODE USING FOREACH (PROPERLY WORKING)
var recipientListWithForEach = new List<Recipient>();
foreach (var item in message.Copies)
{
recipientListWithForEach.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = item
}
});
}
CODE USING LINQ (NOT WORKING, IDK WHY)
var recipientListWithLINQ = new List<Recipient> {
message.Copies.Select(item => new Recipient {
EmailAddress = new EmailAddress {
Address = item
}
});
};
Giving the error message:
not possible convert from "System.Collections.Generic.IEnumerable<Microsoft.Graph.Recipient>" to "Microsoft.Graph.Recipient"