Is there a quicker or more efficient way to add Strings to a List than the below example?:
List<String> apptList = new List<String>();
foreach (Appointment appointment in appointments){
String subject = appointment.Subject;
//...(continues for another 10 lines)
//...And then manually adding each String to the List:
apptList.Add(subject);
//...(continues for another 10 lines)
//And then send off List apptList to another method
}
var apptList = appointments.Select(a => a.Subject).ToList();
I'm not sure if I'm getting your code right, but since your Appointment class is already implementing IEnumerable, you should be able to call ToList() to convert it to a list in one shot.
http://msdn.microsoft.com/en-us/library/bb342261.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With