locked
How to sort this by the first string List<Tuple<string, string, string[]>> keys = new List<Tuple<string, string, string[]>>(); RRS feed

  • Question

  • I want to sort keys based on the first string.  Also can someone point me to how i can do link and lambda expressions.  The key,string values will be formatted like key_name_type, key_name_value, key_something.

    I am going to need to group by section of the string before the last index of _ so I can get items that have _type & _value so i can display them together.  The data is all over the place so i cant hope that sorting will solve the issue.

     List<Tuple<string, string, string[]>> keys = new List<Tuple<string, string, string[]>>();

    Monday, February 1, 2016 5:18 PM

Answers

  • For the sorting part if found a Stack Overflow topic with this:

    var result = keys.OrderBy( x => x.Item1 ).ToList();

    http://stackoverflow.com/questions/5781330/c-sharp-sorting-a-list-using-tuple



    Dennis Bakker | Hobby developer | Microsoft Community Contributor


    If you think this post is an answer to the question, please propose or mark this post as answer.

    If you find this post helpful, please vote for this post.

    • Edited by DennisBakker71 Monday, February 1, 2016 5:25 PM
    • Marked as answer by dbdrtso1 Monday, February 1, 2016 6:07 PM
    • Unmarked as answer by dbdrtso1 Monday, February 1, 2016 6:07 PM
    • Proposed as answer by Kristin Xie Wednesday, February 3, 2016 9:43 AM
    • Marked as answer by Kristin Xie Wednesday, February 17, 2016 9:47 AM
    Monday, February 1, 2016 5:25 PM

All replies

  • For the sorting part if found a Stack Overflow topic with this:

    var result = keys.OrderBy( x => x.Item1 ).ToList();

    http://stackoverflow.com/questions/5781330/c-sharp-sorting-a-list-using-tuple



    Dennis Bakker | Hobby developer | Microsoft Community Contributor


    If you think this post is an answer to the question, please propose or mark this post as answer.

    If you find this post helpful, please vote for this post.

    • Edited by DennisBakker71 Monday, February 1, 2016 5:25 PM
    • Marked as answer by dbdrtso1 Monday, February 1, 2016 6:07 PM
    • Unmarked as answer by dbdrtso1 Monday, February 1, 2016 6:07 PM
    • Proposed as answer by Kristin Xie Wednesday, February 3, 2016 9:43 AM
    • Marked as answer by Kristin Xie Wednesday, February 17, 2016 9:47 AM
    Monday, February 1, 2016 5:25 PM
  • For the sorting part if found a Stack Overflow topic with this:

    var result = keys.OrderBy( x => x.Item1 ).ToList();

    http://stackoverflow.com/questions/5781330/c-sharp-sorting-a-list-using-tuple



    Dennis Bakker | Hobby developer | Microsoft Community Contributor


    If you think this post is an answer to the question, please propose or mark this post as answer.

    If you find this post helpful, please vote for this post.

    Thanks
    Monday, February 1, 2016 6:07 PM