5

这是我之前的问题https://codereview.stackexchange.com/questions/12165/efficency-in-c/12169的后续,我尽我所能使用 BigIntegers 代替 ulongs,但我必须做点什么错误的。我是 C# 新手,我熟悉 Java。这是我最好的转换方法:

using System;

namespace System.Numerics{

      public class Factorial{

             public static void Main(){

             String InString = Console.ReadLine();

             BigInteger num = 0;

             BigInteger factorial = 1;

             try {
                 num = BigInteger.Parse(InString);
                 Console.WriteLine(num);
                 }
             catch (FormatException) {

                  Console.WriteLine("Unable to convert the String into a BigInteger");
            }



            for (BigInteger forBlockvar = num; forBlockvar > 1; forBlockvar--){

                     factorial *= forBlockvar;

            }

            Console.WriteLine("The Factorial for the Given input is:");

            Console.WriteLine(factorial);
    }
}
}

我收到以下错误:

prog.cs(11,18): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(13,18): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(26,22): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference?

这个错误是什么意思,我该如何解决?

4

1 回答 1

10

您需要向 System.Numerics.dll 添加引用(右键单击解决方案资源管理器中的引用并选择添加引用)。

此外,放入using System.Numerics而不是让您的方法的名称空间成为那个(即,将其命名为对您的代码库更具描述性的名称)。

于 2012-05-30T17:15:15.100 回答