2. C# — Check Palindrome in One Line

Is a string the same forwards and backwards? Try this:

using System; using System.Linq; class Program { static void Main() { string word = "level"; // Palindrome check bool isPalindrome = word.SequenceEqual(word.Reverse()); Console.WriteLine(isPalindrome); // True } }

Cool because:

  • No loops.

  • Works for numbers too (12321.ToString()).

✍️ Written by Luis Fernandez Leyva, Software Engineer

Comments

Popular posts from this blog

About Me

3. C# — Get Unique Characters in One Line

C# — Generate a Random String in One Line