
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Program to invert the order of elements in a sequence
Set a string.
char[] ch = { 'd', 'r', 'i', 'v', 'e' }; Console.Write("String = foreach(char arr in ch) Console.Write(arr);
Now, use Queryable Reverse() method to invert the order of elements.
IQueryable<char> res = ch.AsQueryable().Reverse();
Let us see the complete code.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { char[] ch = { 'd', 'r', 'i', 'v', 'e' }; Console.Write("String = "); foreach(char arr in ch) Console.Write(arr); IQueryable<char> res = ch.AsQueryable().Reverse(); Console.Write("
Reversed = "); foreach (char c in res) Console.Write(c); } }
Output
String = drive Reversed = evird
- Related Articles
- C# Program to order array elements in descending order
- C++ Program to find out the distinct elements in a given sequence
- Program to invert bits of a number Efficiently in C++
- C++ Program to Sort Elements in Lexicographical Order (Dictionary Order)
- C# Program to return specified number of elements from the beginning of a sequence
- C# Program to order array elements
- C# Program to check whether the elements of a sequence satisfy a condition or not
- C++ Program to Sort the Elements of an Array in Descending Order
- C++ Program to Sort the Elements of an Array in Ascending Order
- Program to sort each diagonal elements in ascending order of a matrix in C++
- C# Program to find the sum of a sequence
- C# Program to display the last three elements from a list in reverse order
- Program to invert a binary tree in Python
- Java Program to Sort Elements in Lexicographical Order (Dictionary Order)
- Swift Program to Sort Elements in Lexicographical Order (Dictionary Order)

Advertisements