gpt4 book ai didi

c# - 通过控制台界面访问编译器时包含库

转载 作者:可可西里 更新时间:2023-11-01 09:48:16 25 4
gpt4 key购买 nike

灵感来自 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 文件——我需要的是添加到命令/link:[System.Numerics.dll 的 x86 版本的路径]”。搜索结果卡住了我的灵魂:enter image description here

如您所见(或未见),文件比我预计的多得多!此外,它们的大小和内容也不同。我应该包括哪一个?为什么有五个文件,虽然只有两个有存在的意义?/link: 命令是否正确?还是我的思维轨迹完全错误?

最佳答案

我通常发现使用

/r:System.Numerics.dll

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

关于c# - 通过控制台界面访问编译器时包含库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11831043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com