Reverse Each Word Of A Sentence In C#

Introduction 

 
Hello everyone, in this post I'll be creating a program to reverse a complete string.
 
Example 
  • Enter string - Interview Point
  • Reverse String - weivretnI tnioP
You will find the same video here for your reference.
  1. using System;    
  2. namespace ConsoleApp    
  3. {    
  4.     class ReverseStringProgram    
  5.     {    
  6.         static void Main(string[] args)    
  7.         {    
  8.             Console.Write("Enter string: ");    
  9.             string str = Console.ReadLine();    
  10.             string result=string.Empty;    
  11.             string[] arr = str.Split(" ");    
  12.             for (int i = 0; i < arr.Length; i++)    
  13.             {    
  14.                 if (i != arr.Length - 1)    
  15.                 {    
  16.                     result += ReverseString(arr[i]) + " ";    
  17.                 }    
  18.                 else    
  19.                 {    
  20.                     result += ReverseString(arr[i]);    
  21.                 }    
  22.             }    
  23.             Console.WriteLine("Reverse String : {0} ",result);    
  24.             Console.ReadLine();    
  25.         }    
  26.     
  27.         //function to reverse word  
  28.         static string ReverseString(string str)    
  29.         {    
  30.             string result = "";    
  31.             if (string.IsNullOrEmpty(str))    
  32.                 return string.Empty;    
  33.     
  34.             for (int i = str.Length - 1; i >= 0; i--)    
  35.             {    
  36.                 result += str[i];    
  37.             }    
  38.             return result;    
  39.         }    
  40.     }    
  41. }    
I hope you enjoy this post, If you found it helpful, then please like this post and provide feedback that really motivates me to create more useful stuff for you guys. Thanks!