- Use String.ToUpperInvariant instead of ToLower for performance
- Cache call to ToUpperInvariant
- Use SequenceEqual to compare string with its reverse
using System.Linq; class Palindrome { public static bool Check(string word) { var upper = word.ToUpperInvariant(); return upper.SequenceEqual(upper.Reverse()); } }
- using System.Linq;
- class Palindrome
- {
public static bool Check(string word) => word.ToLower() == new string(word.ToLower().Reverse().ToArray());- public static bool Check(string word) {
- var upper = word.ToUpperInvariant();
- return upper.SequenceEqual(upper.Reverse());
- }
- }