简体   繁体   中英

Select n objects from collection based on ranked value

public class A
{
   public int x { get; set; }
}

Then somewhere, a collection:

public List<A> aList { get; set; }

Now, how to select n objects of this list based on highest x values?

LINQ怎么样:

var bestAs = aList.OrderByDescending(a => a.x).Take(n);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM