C# programming
What is the code to check whether a string is a palindrome?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jan MontanoRank #1,295 · 1.3K reputationPosted Sep 20, 2007, 2:39 AM EDT
The code for the palindrome is not that hard. Have you tried to actually coding it yourself? How far have you been with it?
Cheers,
Jan
Mahesh ChandRank #1 · 393.3K reputationPosted Sep 20, 2007, 4:04 AM EDT
Here are some samples including palindrome.
http://www.c-sharpcorner.com/UploadFile/nrsurapaneni/SortSeachNRS11242005061300AM/SortSeachNRS.aspx
AlanRank #669 · 3.6K reputationPosted Sep 20, 2007, 11:47 AM EDT
The code in Mahesh's link deals with a numeric palindrome. The following code deals with a string palindrome:
using System;
class StringPalindrome
{
static void Main()
{
string[] sa = new string[]{"rotor", "caravan", "level", "palindrome"};
foreach (string s in sa)
{
char[] ca = (char[])s.ToCharArray().Clone();
Array.Reverse(ca);
string rev = new string(ca);
string temp = (s == rev) ? "is" : "is not";
Console.WriteLine("\"{0}\" {1} a palindrome", s, temp);
}
Console.ReadLine();
}
}