这是我之前的问题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?
这个错误是什么意思,我该如何解决?
答案 0 :(得分:10)
您需要在System.Numerics.dll中添加引用(右键单击Solution Explorer中的References并选择Add Reference)。
另外,放入using System.Numerics
而不是让你的方法命名空间(即将其命名为代码库更具描述性)。