2012-08-06 31 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