Time for action – checking whether a given string is a palindrome or not
Palindromes are fascinating and it is more fun to find them. Here we shall write a program to demonstrate how we can find whether a string is a palindrome or not, using the operators we have learned so far:
- Copy the following code snippet as a query to LINQPad:
string sentence = "A Man, A Plan, A Canal, Panama"; //Listing the characters of the original input string. var original = sentence .ToLower() .Replace(" ",string.Empty) .Split(',') .SelectMany(c=>c.ToCharArray()); //Storing the reversed one. var reversed = original.Reverse(); //Checking if the original character sequence matches with the //reveresed one. string verdict = original.SequenceEqual(reversed) ? "This is a ...