Jeff
Jeff

Reputation: 1335

How to convert an Int64 to BigInteger in Mono C#?

In MS C#, the following constructor works:

Int64 a = 123;
BigInteger bi = new BigInteger(a);

This does not work in Mono. The compile complains that it can't convert from long to BigInteger (CS1502, CS1503).

Is there anyway to do this?

Upvotes: 0

Views: 1229

Answers (2)

I4V
I4V

Reputation: 35363

See the BigInteger constructors on Mono, http://docs.go-mono.com/?link=T%3aMono.Math.BigInteger%2fC

BigInteger()    
BigInteger(BigInteger)  
BigInteger(byte[])  
BigInteger(uint)    
BigInteger(uint[])  
BigInteger(ulong)   
BigInteger(BigInteger, uint)    
BigInteger(BigInteger.Sign, uint)

There is no constructor accepting long (which is the same as Int64)

Try BigInteger bi = new BigInteger((ulong)a);

or BigInteger bi = new BigInteger((uint)a);

Upvotes: 1

Yakeen
Yakeen

Reputation: 2215

Mono.Math.BigInteger has only constructor accepting ulong. Isn't it System.Numerics.BigInteger You want to use?

https://github.com/mono/mono/blob/master/mcs/class/System.Numerics/System.Numerics/BigInteger.cs

Upvotes: 1

Related Questions