patterncsharpMinor
Determining whether a number is a palindrome
Viewed 0 times
numberdeterminingwhetherpalindrome
Problem
Can someone improve this for me? It seems ugly.
The method should test whether an incoming number is a palindrome and return a Boolean result.
The method should test whether an incoming number is a palindrome and return a Boolean result.
private static bool IsPalindrome(int value)
{
var inverseValue = string.Concat(value.ToString().Reverse());
return inverseValue == value.ToString();
}Solution
Not much there to be ugly to be honest. I guess all I might consider would be the reverse of MrSmith42 and adding functionality to avoid the duplication of
ToString().private static bool IsPalindrome(int value)
{
var valueStr = value.ToString();
return valueStr == string.Concat(valueStr.Reverse());
}Code Snippets
private static bool IsPalindrome(int value)
{
var valueStr = value.ToString();
return valueStr == string.Concat(valueStr.Reverse());
}Context
StackExchange Code Review Q#30847, answer score: 6
Revisions (0)
No revisions yet.