How to initialize BigInteger in C #?

Can someone show me how to use the System.Numerics.BigInteger data type? I tried using this as a link - http://msdn.microsoft.com/en-us/library/system.numerics.biginteger%28VS.100%29.aspx

But the System.Numerics namespace is missing on my computer. I installed VS2010 Ultimate RC and I have .NET Framework 4.0. Can someone help me with this?

+3
source share
7 answers

It should be there, could you add a link?

Right-click your project, click Add Link, then on the left-most tab select System.Numerics

.

+9

.NET 4 ? , , . , System.Numerics.dll .NET Client Profile, .

, , System.Numerics.dll .

+2

System.Numerics.dll ?

+2

, System.Numerics,, . MSDN , .

+2

Visual Studio 2010 . , > .NET, , System.Numerics( System.Numerics.dll) 4.0.0.0 .

, using:

using System.Numerics;

BigInteger :

:

BigInteger x = new BigInteger();
x = BigInteger.Zero; // initializes x to 0
x = BigInteger.One; // initializes x to 1

BigInteger x = new BigInteger();
x = BigInteger(0); // initializes x to 0
x = BigInteger(1); // initializes x to 1

BigInteger x;
x = 0; // initializes x to 0
x = 1; // initializes x to 1

# VB.NET, , BigInteger , : JScript.NET, Phalanger.

+1

You need to add the link System.Numericsyourself, as indicated in other answers, System.Numerics.dllshould be there if you have it installed .NET 4.

Then, if your value is really big, and you try:

var myBigInteger = new BigInteger(50000000000000000000000000000000000000000000);

You will get a compilation error:

Invalid compilation value

The easiest way is to use a text literal:

var myBigInteger = BigInteger.Parse("50000000000000000000000000000000000000000000");
+1
source

Prerequisite: .NET Framework 4

Steps:

  • Add link System.Numerics.dll
  • Add Imports System.Numericsto your class
-1
source

Source: https://habr.com/ru/post/1740948/


All Articles