C# Linq Reverse Method


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("
Reversed String = ");       foreach (char c in res) {          Console.Write(c);       }    } }

Output

String = time
Reversed String = emit

Updated on: 23-Jun-2020

719 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements