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?)

わかった。アセンブリ参照がありません。「シンプルに違いない。システム全体で 2 つの System.Numerics.dll ファイルが必要です。必要なのは、コマンド /link:[System.Numerics.dll の x86 バージョンへのパス] に追加することです」. 検索結果は私の魂を凍らせました:ここに画像の説明を入力

ご覧のとおり (またはそうでない場合もあります)、私が予測したよりも多くのファイルがあります。また、サイズや内容も異なります。どちらを含める必要がありますか? 2 つしか存在ポイントがないのに、なぜ 5 つのファイルがあるのですか? /link:コマンドは正しいですか? それとも、私の思考経路が完全に間違っているのでしょうか?

4

1 に答える 1

6

私は一般的にそれを使用して見つけました

/r:System.Numerics.dll

これにより、コンパイラは GAC 内のアセンブリを見つけることができます。これは、通常、必要な方法です。(確かに先日、コンソール アプリに正確に System.Numerics が必要だったのは問題ありませんでした...)

于 2012-08-06T15:18:35.800 に答える