Time for action – checking whether a sequence is palindromic

Follow the given steps:

  1. Change the language to C# Program in the Language box of LINQPad.
  2. Paste the following query in LINQPad:
    static bool IsPalindromic(string sentence)
      List<string> wordsInOrder = sentence.Split(' ').ToList();
      List<string> wordsInReverseOrder = sentence.Split(' ').Reverse().ToList();
      return wordsInOrder.SequenceEqual(wordsInReverseOrder);
    void Main()
      string response = IsPalindromic("Veni, vidi, vici") ? "\"Veni, vidi, vici\" Is Palindromic":"\"Veni, vidi, vici\" Is Not Palindromic";
      response = IsPalindromic("Nada Ney Nada") ? "\"Nada, Ney, Nada\" Is Palindromic":"\"Nada, Ney, Nada\" Is Not Palindromic";
  3. Run the query. This should ...

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.