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:

  1. 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 ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.