423 characters
foreach (var recipient in subscription.Recipients)
{
switch (recipient.ReceivingMethod)
{
case ReceivingMethod.To:
mail.To.Add(recipient.EMailAdress);
break;
case ReceivingMethod.Copy:
mail.Copy.Add(recipient.EMailAdress);
break;
case ReceivingMethod.BlindCopy:
mail.BlindCopy.Add(recipient.EMailAdress);
break;
}
}
311 characters
mail.To.AddRange(subscription.Recipients.Where(c => c.ReceivingMethod == ReceivingMethod.To))
mail.Copy.AddRange(subscription.Recipients.Where(c => c.ReceivingMethod == ReceivingMethod.Copy))
mail.BlindCopy.AddRange(subscription.Recipients.Where(c => c.ReceivingMethod == ReceivingMethod.BlindCopy))
Either way. Though i personally think the former is the more readable for me
Though if you have printable character OCD, maybe the later
Note : I'm not sure a Dictionary
brings much to the table though
Update from Comments
Zohar Peled : That's also assuming mail.To
, mail.Copy
and mail.BlindCopy
supports
AddRange
- I'm not sure that assumption is correct, since
System.Net.MailMessage
use the MailAddressCollection
classes for To,
CC and BCC, and that class does not support AddRange
and
GolezTrol : Also note that the second option is not just syntactical sugar.
Internally you loop through the recipients 3 times, and each results
in an enumerable that is passed to AddRange
, instead of one by one to
Add. If AddRange
is supported, the end result should be the same,
though, so it's typically not something to worry about