gpt4 book ai didi

c# - 带有函数参数的重载函数的奇怪模糊调用

转载 作者:行者123 更新时间:2023-11-30 17:03:04 25 4
gpt4 key购买 nike

<分区>

假设我有一个重载的方法。一种采用返回 uint 的函数,一种采用返回 int 的函数。

static void test1(Func<uint> f)
{
//things
}
static void test1(Func<int> f)
{
// also things
}

现在我试着这样调用它:

test1(Random.FunctionThatReturnsUints);

但是我在编译时得到了一个不明确的调用错误:

   Error    4   The call is ambiguous between the following methods or
properties: 'RNG_Comparison.Run.test1(System.Func<int>)' and 'RNG_Comparison.Run.test1
(System.Func<uint>)'

这是怎么回事?重载一个函数的全部意义不是让它根据类型隐含地理解你的意思吗?我的意思是,如果我用返回 BigInt 或其他东西的 func 调用它,也许我可以看到编译器的困惑,但这个看起来很简单。

有谁知道我为什么会收到这个错误?

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