2

这个例子的启发,我决定扩展 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: 命令是否正确?或者,也许我的思维轨迹完全错了?

4

1 回答 1

6

我通常发现使用

/r:System.Numerics.dll

让编译器只在 GAC 中找到程序集,这通常是您想要的方式。(当然,前几天我正好需要 System.Numerics 用于控制台应用程序...)

于 2012-08-06T15:18:35.800 回答