Mono.Math.BigInteger is inaccessible due to its protection level

有些话、适合烂在心里 提交于 2019-12-23 16:29:09

问题


So I'm working on a program in C# using ideone and I'm working with Mono for the first time. I'm trying to use the BigInteger class (Mono.Math.BigInteger) but I keep getting errors. Here's me code below. What is going on and how do I fix it? Thanks.

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 < FIB_SEQUENCE_SIZE; i++)
                {
                    if (FibonacciSequence[i] >= lowerBound)
                    {
                        if (FibonacciSequence[i] <= upperBound)
                        {
                            numbersInRange++;
                        }
                        else
                        {
                            continue;   // there is nothing more to find
                        }
                    }
                }

                Console.WriteLine(numbersInRange);
            }
        }

        return 0;
    }
}

These are the errors I'm getting:

prog.cs(9,13): error 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[]' is inaccessible due to its protection level /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) prog.cs(23,27): error 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: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) Compilation failed: 4 error(s), 0 warnings


回答1:


Mono.Math.BigInteger is in the Mono.Security.dll, are you sure you are referencing the right assembly? The compilation errors you are getting suggest you aren't.

While BigInteger is used (internally) inside mscorlib.dll, you can't reference it from there.

Alternatively, there's the 4.0 System.Numerics.BigInteger implementation that you can use by changing your using to System.Numerics and referencing System.Numerics.dll, but it doesn't look as optimized as the Mono.Math one, at least for now.

Unfortunately, Ideone does not seem to allow customizing assembly references, which means that you won't be able to compile either solution at all. You can only file a bug with Ideone.com.




回答2:


Try targeting the .NET 4.0 framework (using dmcs)

Also, from this page:

Yes, but then see this:

http://blogs.msdn.com/bclteam/archive/2007/04/20/visual-studio-code- name-orcas-beta-1-has-been-released-inbar-gazit.aspx

In particular:

some good and constructive feedback from customers and partners that are interested in extended numerical types. We have learned that there are some potential improvements that we can make to this type to better serve their needs. As such, we decided to remove BigInteger from the Beta 1 release of Orcas so that we can address these issues and concerns. -- Jon Skeet"




回答3:


Given that you can't reference the assembly, just add BigInteger.cs to your project directly. Source can be found here: https://github.com/mono/mono/blob/master/mcs/class/Mono.Security/Mono.Math/BigInteger.cs



来源:https://stackoverflow.com/questions/7632692/mono-math-biginteger-is-inaccessible-due-to-its-protection-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!