I have the following code below:
List<long> numbers = new List<long>();
for (long i = 1; i <= 300000000; i++)
{
numbers.Add(i);
}
What I wanted to do is to populate the list from 1-300 million. But when it hit the 67108865, it throws an exception on line 4: Exception of type 'System.OutOfMemoryException' was thrown.
I tried using ulong
but still no luck.
I believe the maximum range for long
data type is 9,223,372,036,854,775,807 but why am I having an error here?
Thanks in advance!
EDIT Thanks for all the answers. It helped my realized that my design is not good. I ended up changing my code design.