BigInteger in C#
As an introduction to the world of parallel computation, my professor gave an assignment in which we were asked to write a program to find all the prime numbers between 1 and some arbitrarily large value. The restriction is that the program must have 10 threads and the work must be shared equally between the threads.
The first step however was to figure out how to represent arbitrarily large integers in C#. A unsigned long
just isn’t going to cut it. I looked around and found that .NET 4.0 adds a BigInteger class in the System.Numerics
namespace.
Being new to Visual Studio and C#, I was a little confused as to why a little red squiggle was appearing under “Numerics” in the line:
First I made sure that the target platform was set to “.NET Framework 4.0” by going to the Project menu, selecting “
Turns out I needed to manually add an assembler reference to System.Numerics.dll
. The process is pretty easy. On the Project Explorer pane, right-click “References”. Click “Add Reference” and select “System.Numerics” from the “.NET” tab.
Success! The red squiggle went away.