I am working on bettering my C# skills, and recently wrote this program to solve a projecteuler.net problem:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99. Find the largest palindrome made from the product of two 3-digit numbers.
The code works and produced the correct answer, but I'm looking to avoid bad code and use best practices. Any critique of changes to make this more efficient would be appreciated! (Also, if there are any WTF's in there, please point them out!)
using System;
using System.Collections.Generic;
using System.Text;
namespace NumericPalindrome {
class Program
{
static void Main(string[] args)
{
long result = 0;
for (int i = 100; i < 1000; i++)
{
for (int k = 100; k < 1000; k++)
{
if (IsPalindrome(i * k))
if ((i * k) > result)
result = i * k;
}
}
Console.WriteLine(result);
}
static bool IsPalindrome(long testNumber)
{
List<int> list = new List<int>();
//Break testNumber into an integer list of its digits
while (testNumber >= 1)
{
list.Add((int)(testNumber % 10));
testNumber /= 10;
}
List<int> reverseList = new List<int>(list);
reverseList.Reverse();
bool palindrome = true;
for (int i = 0; i < list.Count; i++)
{
if (list[i] != reverseList[i])
palindrome = false;
}
return palindrome;
}
}
}