c# - 如何修复 "The type or namespace name could not be found"?

标签 c#

这是我之前问题的后续问题 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?

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

最佳答案

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

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

关于c# - 如何修复 "The type or namespace name could not be found"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10850250/

相关文章:

c# - Intellitrace 和 Windows 服务

c# - 静态调用实例方法

c# - 将一个类中的数据传递给另一个类中的函数

c# - 关闭的局部变量与匿名操作中的预期不同

c# - 反序列化未知类型的 JSON(Google Map API)

c# - 如何从 NuGet 包获取的 RCL 导入 Razor 页面?

c# - 直接查询 Power BI - 无法加载大数据视觉效果

c# - 如何制作可以添加到 Windows.Foundation.Collections.ValueSet 的类

C# 删除 HTML 代码并合并段落

c# - Roslyn - CSharpCompilation