Use Linq Aggregate the reverse a string : Aggregate « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;

    class Program
    {
        private static string ReverseString(string sentence)
        {
            List<string> words = new List<string>(sentence.Split(' ').ToList());

            return words.Aggregate((a, b) => b + " " + a);            
        }

        static void Main(string[] args)
        {
            string sentence = "this is a test";
            string result = ReverseString(sentence);
            Console.WriteLine(result);
        }        
    }








22.16.Aggregate
22.16.1.Use Aggregate on an array
22.16.2.Use Aggregate on an array with tenary operator
22.16.3.Aggregate Prototype
22.16.4.Aggregate and Sum
22.16.5.Aggregate for string length
22.16.6.Aggregate string and int value
22.16.7.Aggregate three values
22.16.8.Aggregate two string values
22.16.9.Aggregation with integer value
22.16.10.Aggregation with string value
22.16.11.Use Linq Aggregate the reverse a string