I'm new to Linq and I'm wondering why the First() method call is needed when ordering by the County in the following query. Also, after knowing why it is needed, could the same result be accomplished by using the Last() method?
var hsQ = from hspt in hospitals
orderby hspt.City
group hspt by hspt.County into hsptGroup
orderby hsptGroup.First().County
select hsptGroup;
Note: The above example is part of a Question/Answer from a book I'm reading, and the type hospitals is not defined explicitly for me to see.
That is because
hsptGroup
holds a group of hospitals, not a single hospital.Even though all the hospitals in this group have the same county, you still need to specify
.First()
, so you can reference a single hospital's county.