You want to multiply 2 million numbers all together, but there is a problem.
The problem is memory limitation. to hold a big number you have to use BigInteger
class inside System.Numerics
namespace.
You can use this reference by adding Using keyword in top of your project.
using System.Numerics;
If the compiler did not recognize Numerics
then You need to add an assembly reference to System.Numerics.dll
.
Your code should look like this.
string inputFilename = @"C:\intput.txt"; // put the full input file path and name here.
var lines = File.ReadAllLines(inputFilename); // put text lines into array of string.
BigInteger big = new BigInteger(1); // create the bigInt with value 1.
foreach (var line in lines) // iterate through lines
{
big *= Convert.ToInt32(line); // Multiply bigInt with each line.
}
string outputFilename = @"C:\output.txt"; // put the full output file path and name here
File.WriteAllText(outputFilename, big.ToString()); // write the result into text file
This may take a long time to complete. but this all depends on hardware that is operating. You may get memory overflow exception during this task which depends on amount of memory you have.