简体   繁体   English

如何在Mono C#中将Int64转换为BigInteger?

[英]How to convert an Int64 to BigInteger in Mono C#?

In MS C#, the following constructor works: 在MS C#中,以下构造函数工作:

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

This does not work in Mono. 这在Mono中不起作用。 The compile complains that it can't convert from long to BigInteger (CS1502, CS1503). 编译抱怨它无法从long转换为BigInteger(CS1502,CS1503)。

Is there anyway to do this? 反正有没有这样做?

See the BigInteger constructors on Mono, http://docs.go-mono.com/?link=T%3aMono.Math.BigInteger%2fC 请参阅Mono上的BigInteger构造函数, http: //docs.go-mono.com/?link = T%3aaMono.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) 没有构造函数接受long (which is the same as Int64)

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

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

Mono.Math.BigInteger has only constructor accepting ulong. Mono.Math.BigInteger只有构造函数接受ulong。 Isn't it System.Numerics.BigInteger You want to use? 是不是System.Numerics.BigInteger你想用吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM