2012-08-06 48 views
2

this启发示例我决定展开Factorial类。通过控制台界面访问编译器时包含库

using System; 
using System.Numerics; 

namespace Functions 
{ 
    public class Factorial 
    { 
     public static BigInteger CalcRecursively(int number) 
     { 
      if (number > 1) 
       return (BigInteger)number * CalcRecursively(number - 1); 
      if (number <= 1) 
       return 1; 

      return 0; 
     } 

     public static BigInteger Calc(int number) 
     { 
      BigInteger rValue=1; 

      for (int i = 0; i < number; i++) 
      { 
       rValue = rValue * (BigInteger)(number - i);     
      } 

      return rValue; 

     }  
    } 
} 

我已经使用了System.Numerics,默认情况下它没有包括在内。因此,命令
csc /target:library /out:Functions.dll Factorial.cs DigitCounter.cs输出:

Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 
Copyright (C) Microsoft Corporation. All rights reserved. 

Factorial.cs(2,14): error CS0234: The type or namespace name 'Numerics' does not 
     exist in the namespace 'System' (are you missing an assembly reference?) 
DigitCounter.cs(2,14): error CS0234: The type or namespace name 'Numerics' does 
     not exist in the namespace 'System' (are you missing an assembly 
     reference?) 
Factorial.cs(8,23): error CS0246: The type or namespace name 'BigInteger' could 
     not be found (are you missing a using directive or an assembly 
     reference?) 
Factorial.cs(18,23): error CS0246: The type or namespace name 'BigInteger' could 
     not be found (are you missing a using directive or an assembly 
     reference?) 
DigitCounter.cs(8,42): 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文件 - 我需要的是添加到命令/链接:[System.Numerics.dll的x86版本的路径]”。搜索结果冻结了我的灵魂:enter image description here

正如你所看到的(或没有)有比我预测的更多的文件!而且,它们的大小和内容各不相同。我应该包括哪一个?为什么有五个文件,虽然只有两个文件存在?/link:命令是否正确?或者,也许我完全错了我的思路?

回答

6

我通常发现,使用

/r:System.Numerics.dll 

让编译器只要找到在GAC中,这通常是你想要的方式组装。 (当然,当我需要控制台应用程序的System.Numerics时,它确实很好......)

+0

很奇怪,在csc的命令手册('csc /?')中甚至没有提到这样有用的命令。 – 0x6B6F77616C74 2012-08-06 15:23:26

+0

@kowalt:是的。 '/ r'只是'/ reference'的简写形式。 – 2012-08-06 15:24:23

+0

我的overshight。无论如何,感谢您以可访问的方式描述它。 – 0x6B6F77616C74 2012-08-06 15:31:19