# Sorting a jagged list based on 2nd entry

**URL:** https://discussions.unity.com/t/sorting-a-jagged-list-based-on-2nd-entry/44392
**Category:** Questions & Answers
**Created:** [June 14, 2012, 6:33pm UTC](https://discussions.unity.com/t/sorting-a-jagged-list-based-on-2nd-entry/44392 "2012-06-14T18:33:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hijinxbassist](https://avatars.discourse-cdn.com/v4/letter/h/848f3c/32.png) [@hijinxbassist](https://discussions.unity.com/u/hijinxbassist)
#### Post date: [June 14, 2012, 6:33pm UTC](https://discussions.unity.com/t/sorting-a-jagged-list-based-on-2nd-entry/44392/1 "2012-06-14T18:33:04Z")

</div>

Hi, having trouble figuring out a good way to sort my jagged list, each base list contains 6 values. I need to sort the list based on the 2nd value.

Heres an example of what might be in the list

```
john 2 4 150 ...
sam 4 2 402 ...
kel 1 4 233 ...
ida 3 1 523 ...

```

I want to sort it so it looks like, the 2nd value being compared.

```
kel 1 4 233 ...
john 2 4 150 ...
ida 3 1 523 ...
sam 4 2 402 ...

```

Im kinda lost trying to figure out how to sort a jagged list, if someone can help id be more than greatful. Thanks!

---

<div class="post-metadata">

### Author: ![whydoidoit](https://avatars.discourse-cdn.com/v4/letter/w/90db22/32.png) [@whydoidoit](https://discussions.unity.com/u/whydoidoit)
#### Post date: [June 14, 2012, 6:45pm UTC](https://discussions.unity.com/t/sorting-a-jagged-list-based-on-2nd-entry/44392/2 "2012-06-14T18:45:16Z")

</div>

Sorry first answer was a bit of madness!!!

Right well if it was a List of Lists of Object in c#:

```
using System.Collections.Generic;
using System.Linq;

  ...
  var myBaseList = new List<List<object>>();
  var sorted = myBaseList.OrderBy(c=>(int)c[1]).ToList();

```

Or an array list of array lists:

```
 using System.Linq;

  var sorted = myBaseList.OrderBy(c=>(int)((ArrayList)c)[1]).ToArray();

```

Which gives you an array of array lists.
