How to Reverse Order of the Given String

Introduction

In this article, we are going to explore how to reverse the order of the given string.

Eg.

  1. Input: This is Kirtesh Shah
  2. Result: Shah Kirtesh is This

This is an essential technical interview question that may be posed to beginner, intermediate, and experienced candidates.

We previously covered,

  1. How to Reverse Number in C#
  2. How to Reverse a String in C#
  3. Palindrome String Program in C#
  4. Palindrome Number in C#

Let’s start,

Reverse order of the given string.

First, create the Asp.Net Core Console application and write the below code in the program.cs file.

Console.WriteLine("Enter a string");
var str = Console.ReadLine();

var strArray = str.Split(" ").Reverse();
var reverseOrder = String.Join(" ", strArray);

Console.WriteLine($"{reverseOrder}");
Console.ReadLine();

Output

Output

That’s all for this article. Hope you enjoy this article and learn something new.


Similar Articles