The Program in C# Program that takes letters & display them in reverse order in Given array is given below:
using System;
namespace ReverseLetters
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, enter a word here to find it in reverse order:");
string word = Console.ReadLine();
char[] wordArray = word.ToCharArray();
Array.Reverse(wordArray);
Console.WriteLine("Okay,the word in reverse order is: ");
Console.WriteLine(new string(wordArray));
}
}
}
Output:
Hello Codeauri Family, enter a word here to find it in reverse order:coderecode
Okay,the word in reverse order is:
edoceredoc
Pro-Tips💡
Here are the step by step execution of above program:
- The using System; statement is a directive that tells the compiler to include the System namespace in the program.
- The namespace ReverseLetters defines a namespace that encapsulates the Program class.
- The class Program contains a Main method, which is the entry point of the application.
- The Main method starts by displaying a message asking the user to enter a word.
- The user’s input is stored in a string variable called “word”.
- The ToCharArray() method is used to convert the string into a character array.
- The Array.Reverse() method is used to reverse the order of the elements in the character array.
- The new string() constructor is used to create a new string from the reversed character array.
- Finally, the reversed word is displayed to the user using Console.WriteLine().
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.