This program tells us whether the given string is a palindrome or not. But before we proceed further, it is very important to know what a palindrome is. A palindrome is a word, number, or sequence of characters which is the same whether we read it forward or from backward.
Example
mom, madam, racecar, 1001, and many more.
Now, let us move to the C# coding part. The code is simple so there is no need to explain it.
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the String");
- Console.WriteLine("------------------");
- string GetText = Console.ReadLine();
- Program p = new Program();
- p.Palindrome(GetText);
- Console.ReadLine();
- }
- public void Palindrome(string str)
- {
- string rev = "";
- for(int i=str.Length-1;i>=0;i--)
- {
- rev += str[i].ToString();
- }
- Console.WriteLine("Reversed String:");
- Console.WriteLine("-----------------");
- Console.WriteLine(rev);
- Console.WriteLine("-----------------");
- if(rev==str)
- {
- Console.WriteLine("The given string {0} is Palindrome",str);
- }
- else
- {
- Console.WriteLine("The given string {0} is not Palindrome",str);
- }
- }
- }
Hope you find this helpful
Abubakr MahdiPosted Aug 8, 2019, 12:00 AM
Great Job...
Pankajkumar PatelPosted Jul 30, 2019, 12:05 AM
Good one ...
Farukh SharipovPosted Jul 29, 2019, 11:27 PM
This is case sensitive, plus you can accomplish this in one line str.toLower() == str.revrse().toLower()