2. C# — Check Palindrome in One Line
Is a string the same forwards and backwards? Try this:
✅ Cool because:
-
No loops.
-
Works for numbers too (
12321.ToString()
).
✍️ Written by Luis Fernandez Leyva, Software Engineer
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
Post a Comment