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.Dump();
    
      response = IsPalindromic("Nada Ney Nada") ? "\"Nada, Ney, Nada\" Is Palindromic":"\"Nada, Ney, Nada\" Is Not Palindromic";
      response.Dump();
    }
  3. Run the query. This should ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.