How to order by descending a Tuple in C#

1 Answer

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Tuple<int, int>[] tuples = new Tuple<int, int>[5];

            tuples[0] = new Tuple<int, int>(1, 5);
            tuples[1] = new Tuple<int, int>(10, 12);
            tuples[2] = new Tuple<int, int>(7, 3);
            tuples[3] = new Tuple<int, int>(13, 150);
            tuples[4] = new Tuple<int, int>(200, 99);

            var OrderedTuples = tuples.OrderByDescending(n => n.Item1);

            foreach (var item in OrderedTuples)
                Console.WriteLine(item);
        }
    }
}


/*
run:
  
(200, 99)
(13, 150)
(10, 12)
(7, 3)
(1, 5)
 
*/

 



answered Jan 9, 2017 by avibootz

Related questions

1 answer 105 views
1 answer 174 views
1 answer 107 views
1 answer 137 views
...