It contains a program to reverse a string and to check whether a Entered string is palindrome or not.
- using System;
- namespace palindrome
- {
- class Program
- {
- static void Main(string[] args)
- {
- string s,revs="";
- Console.WriteLine(" Enter string");
- s = Console.ReadLine();
- for (int i = s.Length-1; i >=0; i--) //String Reverse
- {
- revs += s[i].ToString();
- }
- if (revs == s) // Checking whether string is palindrome or not
- {
- Console.WriteLine("String is Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
- }
- else
- {
- Console.WriteLine("String is not Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
- }
- Console.ReadKey();
- }
- }
- }

Onkar SharmaPosted Dec 31, 2024, 3:32 PM
If you're looking to explore a detailed explanation of the Palindrome program in C#, check out the following resource: https://www.c-sharpcorner.com/article/explaining-palindrome-program-in-c-sharp/
Aswin VpPosted Aug 21, 2019, 1:17 PM
None of these codes are efficient as mine :p Static bool isPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; }
Aswin VpPosted Aug 21, 2019, 1:15 PM
None of these codes are efficient as mine :p Static bool isPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; }
Pabitra ChhataiPosted Nov 12, 2018, 12:44 PM
Before comparing string convert it to upper or lower then it will work for both 'Malayalam'.as its not working for this string like if (revs.ToLower()==s.ToLower()) in the above example
Ankit SahuPosted Jan 20, 2018, 12:44 PM
Using System;using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { public class Palindrome { static void Main() { string str = "Aba", rev = ""; foreach (char c in str) { rev = c+rev; } if(str.Equals(rev,StringComparison.OrdinalIgnoreCase)) Console.WriteLine("String is Palindrome"); else Console.WriteLine("String is not Palindrome"); Console.ReadKey(); } } }
Patel SoniyaPosted Apr 12, 2017, 7:17 AM
Thanks nice explanation ..........................
Arvind PandeyPosted Nov 12, 2016, 8:41 AM
String GetValue = txtBody.Text(); string ReturnStr = GetValue.SequenceEqual(GetValue .Reverse());
Abhay KumarPosted Jan 18, 2016, 7:33 AM
string strVal = "Malayalam".ToLower(); char[] alpha = strVal.ToCharArray(); int i = 0; int strlen = strVal.Length; for ( i = 0; i <= alpha.Length-1; i++) {string FirstVal = alpha.GetValue(i).ToString(); string LastVal = alpha.GetValue(strlen-1).ToString(); if (FirstVal == LastVal){strlen = strlen - 1;} else {Console.WriteLine("this is Not pallindrome");return;} }
Phaneendra ChakravaramPosted Jan 10, 2016, 12:18 PM
Thank u
Roshan HalwaiPosted Sep 21, 2015, 8:16 AM
Here is my code without using any for loops:using System;public class Test{ public static void Main() { string s=Console.ReadLine(); char[] rev=s.ToCharArray(); Array.Reverse(rev); string revs=new string(rev); if(s.Equals(revs)) Console.WriteLine("Palindrome"); else Console.WriteLine("Not Palindrome"); } }
Ashwani ChaudharyPosted Jul 1, 2015, 3:26 PM
Can any one help me to make a program in c# to find out number of palindrome substring in a string
Ujjval ShuklaPosted Jun 27, 2015, 6:48 AM
It works only for Case sensitive string.Like according to above Program 'Malayalam' is Not Palindrome while 'malayalam' is Palindrome.
Gurunath NavalePosted Apr 30, 2014, 10:10 AM
Here is more efficient code for checking palindrome string public static bool palindrome(string str) { if (str.Length < 2) return false; for (int i = 0, len = str.Length - 1; i < str.Length / 2; i , len--) { if (str[i] == '.') i ;// This code is to ignore . if (str[len] == '.') len--;//this code is to ignore . if (str[i] != str[len]) return false; } return true; }