2

I have a JArray as below:

_ja_data = new JArray(_ja.OrderBy(obj => (string)obj["km"]));

it contains lots of route data of a trip, I did OrderBy "km" but I only want to show 10 data.

How to do Top n on JArray?

DevDon
  • 101
  • 7

1 Answers1

3

I think .Take(N) is what you're looking for. Take takes the first N elements into a new list. So try:

_ja_data = new JArray(_ja.OrderBy(obj => (string)obj["km"])).Take(10);

Credit goes to: How to get first N elements of a list in C#?

bar9833625
  • 295
  • 2
  • 11
  • 1
    Normally you would flag as _duplicate_ but I see you don't have the rep.... _yet_. ;) +1 regardless –  Aug 27 '20 at 05:47