1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

ordering two lists of objects

Discussion in 'Programming & Webmastering' started by ste2425, Nov 19, 2013.

  1. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,503 (1.42/day)
    Thanks Received:
    416
    Location:
    Huddersfield, uk
    I have a list of of object 'build'

    Code:
    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

    Code:
    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
     
    Last edited: Nov 19, 2013
  2. Castiel

    Castiel

    Joined:
    May 5, 2008
    Messages:
    3,319 (1.33/day)
    Thanks Received:
    310
    To suggest, I would recommend seeking help on Stack Overflow if you don't get a response from anyone here.
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page