2013-02-11 85 views
0

在MS C#,下面的構造原理:如何將Int64轉換爲Mono C#中的BigInteger?

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

這並不單聲道工作。編譯器會抱怨它無法從long轉換爲BigInteger(CS1502,CS1503)。

有沒有辦法做到這一點?

+0

在這裏有什麼幫助嗎? http://stackoverflow.com/questions/7632692/mono-math-biginteger-is-inaccessible-due-to-its-protection-level – jjxtra 2013-02-11 21:40:51

回答

1

參見單聲道的BigInteger構造,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) 

沒有構造接受long (which is the same as Int64)

嘗試BigInteger bi = new BigInteger((ulong)a);

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

+0

是的,它看起來像'Mono.Math.BigInteger'是一個無符號(即,總是非負的)整數,一個「自然」數字。當'a'是一個有符號類型,而不是'const'時,編譯時不能保證'a'是非負的。因此,使'a'恆定,或檢查其符號並投射到'UInt64'。 – 2013-02-11 22:18:25