由于其保护级别,Mono.Math.BigInteger无法访问
所以我正在使用ideone在C#中编写一个程序,我第一次使用Mono。 我正在尝试使用BigInteger类(Mono.Math.BigInteger),但我一直在收到错误。 这是我下面的代码。 发生了什么,我该如何解决? 谢谢。
using System; using Mono.Math; public class TFIB { public static int Main() { const int FIB_SEQUENCE_SIZE = 300; BigInteger[] FibonacciSequence = new BigInteger[FIB_SEQUENCE_SIZE]; // Calculate Fibonacci Sequence FibonacciSequence[0] = 0; FibonacciSequence[1] = 1; for (int i = 2; i < FIB_SEQUENCE_SIZE; i++) { FibonacciSequence[i] = FibonacciSequence[i - 1] + FibonacciSequence[i - 2]; } while (true) { string[] tokenInput = Console.ReadLine().Split(' '); Mono.Math.BigInteger lowerBound = Mono.Math.BigInteger.Parse(tokenInput[0]); BigInteger upperBound = BigInteger.Parse(tokenInput[1]); if (lowerBound == 0 && upperBound == 0) { break; // ending sequence found } else { // find the number of fibonacci sequences int numbersInRange = 0; for (int i = 0; i = lowerBound) { if (FibonacciSequence[i] <= upperBound) { numbersInRange++; } else { continue; // there is nothing more to find } } } Console.WriteLine(numbersInRange); } } return 0; } }
这些是我得到的错误:
prog.cs(9,13):错误CS0122: Mono.Math.BigInteger' is inaccessible due to its protection level /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) prog.cs(9,23): error CS0122:
Mono.Math.BigInteger []’由于其保护级别/usr/lib/mono/2.0/mscorlib.dll(与先前错误相关的符号位置)prog.cs而无法访问( 23,27):错误CS0122: Mono.Math.BigInteger' is inaccessible due to its protection level /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) prog.cs(24,17): error CS0122:
由于其保护级别/usr/lib/mono/2.0/mscorlib.dll(与先前错误相关的符号的位置),Mono.Math.BigInteger’无法访问。编译失败:4个错误,0警告
Mono.Math.BigInteger
在Mono.Security.dll
,你确定你引用了正确的程序集吗? 你得到的编译错误表明你不是。
虽然BigInteger
(内部)在mscorlib.dll
,但您无法从那里引用它。
或者,有一个4.0 System.Numerics.BigInteger
实现,您可以通过将您的using
更改为System.Numerics
并引用System.Numerics.dll
using
它,但它看起来不像Mono.Math
那样优化,至少现在。
不幸的是,Ideone似乎不允许自定义程序集引用,这意味着您根本无法编译任何解决方案。 您只能向Ideone.com提交错误。
尝试定位.NET 4.0框架(使用dmcs)
另外,从他的页面 :
是的,但是看到这个:
特别是:
来自对扩展数字类型感兴趣的客户和合作伙伴的一些好的和建设性的反馈。 我们已经了解到,我们可以对这种类型进行一些潜在的改进,以更好地满足他们的需求。 因此,我们决定从Orcas的Beta 1版本中删除BigInteger ,以便我们可以解决这些问题和疑虑。 – Jon Skeet“
鉴于您无法引用程序集,只需将BigInteger.cs直接添加到项目中即可。 来源可以在这里找到: https : //github.com/mono/mono/blob/master/mcs/class/Mono.Security/Mono.Math/BigInteger.cs