-3
  List<int> pal=new List<int>();
        List<int> nums = new List<int>();
        var thdigit1 = 1;
        var thdigit2 = 999;
        while (thdigit2>=1)
        {
            var holder=thdigit1* thdigit2;
            nums.Add(holder);
            thdigit2 -= 1;
            if (thdigit2==0)
            {
                thdigit2 = 999;
                thdigit1 += 1;
            }
        }

I am getting a memory overload problem for too much in the list. Is there a certain limit that my computor can handle? Thanks

Kieran
  • 13
  • 1

1 Answers1

2

The problem is when thdigit2 is 1, it is still continuing the while loop,

while (thdigit2>=1)

reduced by 1 and then becomes 0

thdigit2 -= 1;

and... reseted back to 999.

if (thdigit2==0)
{
    thdigit2 = 999;
    thdigit1 += 1;
}

Thus you get memory overflow as you never gets out of the while loop.

To fix it, you probably need to add another termination condition in your while loop:

while(thdigit2 >= 1 && thdigit1 <= 10) //example
Ian
  • 30,182
  • 19
  • 69
  • 107