# ordering two lists of objects



## ste2425 (Nov 19, 2013)

I have a list of of object 'build'


```
public class build
   {
       public Int32 id { get; set; }
       public string number { get; set; }
       public string status { get; set; }
       public string buildTypeId { get; set; }
       public string branchName { get; set; }
       public string startDate { get; set; }
       public string href { get; set; }
   }
```

Which im sorting into two lists according to the buildTypeId then ordering according to the build number(property number) by


```
var finish = BuildList.Where(y => y.buildTypeId == "bt11").OrderBy(x => x.number);
var start = BuildList.Where(y => y.buildTypeId == "bt19").OrderBy(x => x.number);
```

build number is unique to the build im pulling the start and finish info on. So in each start and finish list build number will not be duplicated and its how i ensure i get the matching start and finish build object. Trouble is if a build failed it wont have a matching finish object or if the build is currently in progress when i get the initial data. Which means i have a start list smaller then the finish list and the two lists don't match up. 

What i want to do next but not sure how is order both lists so they match, ie index 0 of both have the same build number then index 1 have the same build number etc down the list. which will work with the .OrderBy(x => x.number). However when there is no matching finish object with that number id like to insert a default build object Instead and its this bit im struggling with. Im competent with LINQ but not enough to solve this last bit, is it even possible with LINQ?

EDIT: DAM sorry this happens every bloody time, I think I may have found a possible solution .FirstOrDefault() Still looking into it but it seems good so far. It was the one Google link I didn't click on. I wouldn't mind but ive used in the past too and completely forgot. 

Thanks everybody


----------



## Castiel (Nov 20, 2013)

To suggest, I would recommend seeking help on Stack Overflow if you don't get a response from anyone here.


----------

