![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements