I've cobbled together as best I could an answer using the format found here provided. I lack full understanding of how the LINQ query works and don't want to use it without understanding well the how and why of what's occurring.
Regarding NumberIsAPalindrome, I tried to use number.ToString().Reverse().ToString() but was unable to achieve the results I expected, so I reverted to a for...loop. Is this achievable?
class PalindromNumber
{
public string GetPalindromeNumber(int maxNumber = 999)
{
var query = from first in ThreeDigitNumbers()
from second in ThreeDigitNumbers()
let product = first * second
where NumberIsAPalindrome(product)
select product;
return query.Max().ToString();
}
public int[] ThreeDigitNumbers()
{
int[] numberArray = new int[900];
for (int i = 0; i < numberArray.Length; i++)
{
numberArray[i] = 999 - i;
}
return numberArray;
}
public bool NumberIsAPalindrome(int number)
{
int reversedValue=0;
string stringNumber = number.ToString();
for (int i= stringNumber.Length-1; i >= 0; i--)
{
reversedValue += (int.Parse(stringNumber[i].ToString()) * (int)Math.Pow(10,i) );
}
return number == reversedValue;
}
}
number.ToString().Reverse().ToString(). It does seem a bit confusing looking at that part now. \$\endgroup\$