Let me explain using this code sample:
var commands1 = new List<int> { 1 };
var lessons = new List<lesson>
{
new lesson
{
hours = new List<hour>
{
new hour { period = 1 }
}
}
};
List<command> commands2
{
get
{
return (
from o in commands1
select new command
{
hour = ??开发者_高级运维??;
}
).ToList();
}
}
and in place of the ????
. I need to get the hour
object of which period
corresponds to o
. Normally I would loop through lessons
, then loop through hours
to check hour.period
but I don't know how to do that in a LINQ query.
I hope that is clear enough (and that I paraphrased the code correctly).
hour = lessons.SelectMany(l => l.hours).Where(h => h.period == o);
精彩评论