C# Linq Reverse Method

CsharpProgrammingServer Side Programming

Reverse the elements in an array, using the Reverse method.

Here is our character array.

char[] ch = { 't', 'i', 'm', 'e' };

Now use the Reverse() method with AsQueryable() method to get the reverse.

ch.AsQueryable().Reverse();

Let us see the complete code.

Example

 Live Demo

using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
   public static void Main() {
      char[] ch = { 't', 'i', 'm', 'e' };
      Console.Write("String = ");
      foreach(char arr in ch) {
         Console.Write(arr);
      }
      IQueryable<char> res = ch.AsQueryable().Reverse();
      Console.Write("\nReversed String = ");
      foreach (char c in res) {
         Console.Write(c);
      }
   }
}

Output

String = time
Reversed String = emit
raja
Published on 14-Sep-2018 15:08:04
Advertisements