To find the
object with the smallest attribute value, you can use the aggregation function of Linq. Please consider the following methods:
DateOfBirth
The following is its working principle: Person
var firstBorn = People.Aggregate((curMin, x) => (curMin == null || (x.DateOfBirth ?? DateTime.MaxValue) < (curMin.DateOfBirth ?? DateTime.MaxValue)) ? x : curMin);
The method is used to traverse the collection and accumulate a single result.
The anonymous function passed to uses two parameters: Aggregate
Aggregate
: The current
curMin
DateOfBirth
x
values; if it is NULL, set it to Person
(assuming that there is no valid Compare determine which object has earlier birth date. (x.DateOfBirth ?? DateTime.MaxValue)
x
DateOfBirth
DateTime.MaxValue
The cumulative process continues until all the DateOfBirth
objects in the assessment set will eventually produce the
(curMin == null || (x.DateOfBirth ?? DateTime.MaxValue) < (curMin.DateOfBirth ?? DateTime.MaxValue))
The above is the detailed content of How to Find the Person with the Minimum or Maximum Property Value Using LINQ?. For more information, please follow other related articles on the PHP Chinese website!