受这个例子的启发,我决定扩展 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 文件 - 我需要添加到命令 /link:[Path to the x86 version of System.Numerics.dll]”。搜索结果冻结了我的灵魂:
如您所见(或没有),文件比我预期的要多得多!此外,它们的大小和内容不同。我应该包括哪一个?为什么有五个文件,虽然只有两个有存在的意义?/link: 命令是否正确?或者,也许我的思维轨迹完全错了?