How to order array of string alphabetically by reversed strings in C#

1 Answer

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = { "c#", "java", "c", "c++", "python" };

            var orderedArray = arr.OrderBy(a => new string(a.ToCharArray().Reverse().ToArray()));

            foreach (var s in orderedArray)
                Console.WriteLine(s);
        }
    }
}


/*
run:
  
c#
c++
java
c
python
 
*/

 



answered Jan 8, 2017 by avibootz

Related questions

1 answer 126 views
1 answer 139 views
1 answer 233 views
4 answers 407 views
1 answer 139 views
...