Introduction
In the below content, you will find simple, different, yet important ways to find whether a string /word is palindrome or not.
Way 1 : Using Array. Reverse () Method
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProgrammingInterviewFAQ.Palindrome
- {
- class UsingReverseMethod {
- static void Main() {
- Console.WriteLine("Enter the String to check:");
- String input = Console.ReadLine();
- string output = string.Empty;
- char[] inputtochar = input.ToCharArray(); // this line converts the string to char for reversing
- Array.Reverse(inputtochar); // this line actually reverse the Converted CharArray
- output = new string(inputtochar); //this line converts the ReversedcharArray back to string
- if (input == output) {
- Console.WriteLine("Palidrome");
- Console.ReadLine();
- } else {
- Console.WriteLine("Not palindrome");
- Console.ReadLine();
- }
- }
- }
- }using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProgrammingInterviewFAQ.Palindrome
- {
- class UsingReverseMethod {
- static void Main() {
- Console.WriteLine("Enter the String to check:");
- String input = Console.ReadLine();
- string output = string.Empty;
- char[] inputtochar = input.ToCharArray(); // this line converts the string to char for reversing
- Array.Reverse(inputtochar); // this line actually reverse the Converted CharArray
- output = new string(inputtochar); //this line converts the ReversedcharArray back to string
- if (input == output) {
- Console.WriteLine("Palidrome");
- Console.ReadLine();
- } else {
- Console.WriteLine("Not palindrome");
- Console.ReadLine();
- }
- }
- }
- }
Enter the string to check: Redivider
Palindrome
Enter the String to check: Karthik
Not Palindrome
Way 2: Without using Array. Reverse() Method
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProgrammingInterviewFAQ.Palindrome
- {
- class WithoutUsingReverseMethod {
- static void Main(string[] args) {
- Console.WriteLine("Enter the String to check:");
- String input = Console.ReadLine(); //getting the value(input) from user
- string output = string.Empty;
- int inputlength = input.Length; // get the length to perform loop
- for (int i = 0; i < inputlength;) {
- output += input[inputlength - 1].ToString(); //Important :Transfer one string variable to another string variable
- //At the specified index
- inputlength--; //decrease the index to get the value in reverse order
- }
- if (input == output) // finally check with input
- {
- Console.WriteLine("Palidrome");
- Console.ReadLine();
- } else {
- Console.WriteLine("Not palindrome");
- Console.ReadLine();
- }
- }
- }
- }
Enter the String to check: Redivider
Palindrome
Enter the String to check: Karthik
Not Palindrome
Conclusion
As a developer, even after we have experience, when it comes to preparation for an interview, there is always a necessity of taking a look at this kind of simple program. And, there are different ways of achieving the same thing. So I thought to put those in one place which we can easily go through.
In the future, I will update this blog if I get any other ways to achieve the same. The source code is in the attachment section.
I hope it will be helpful, especially for job seekers; kindly let me know your thoughts or feedback.

Karthik ElumalaiPosted Aug 23, 2016, 10:05 PM
My Pleasure and happy that it helped you..Thanks for your feedbackRumbidzai Abigail
Rumbidzai MuserepwaPosted Aug 23, 2016, 4:28 PM
Thank you
Karthik ElumalaiPosted Aug 19, 2016, 4:00 AM
Thank youBhuvan Pandey
Bhuvan PandeyPosted Aug 19, 2016, 2:30 AM
Good