gpt4 book ai didi

c# 方法类型推断的麻烦

转载 作者:太空宇宙 更新时间:2023-11-03 12:04:03 25 4
gpt4 key购买 nike

<分区>

我无法让 C# 方法类型推断为我工作,我实际上有以下示例,但这会产生错误。

CS0411 无法从用法中推断方法“Test.Connect(T1)”的类型参数。尝试明确指定类型参数。

public void Main()
{
new Test<int>().Connect(new Test2()); // CS0411 The type arguments for method 'Test<int>.Connect<T1, T2>(T1)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
}

public class Test2 : ITest<Test<int>, Delegate>
{

}

public class Test<T>
{
public void Connect<T1, T2>(T1 entity)
where T1 : ITest<Test<int>, T2>
where T2 : Delegate
{
}
}

public interface ITest<T1, T2>
where T1 : Test<int>
where T2 : Delegate
{
}

编译器是否应该能够从给定的类中推断出参数 T1 和 T2?我想应该是这样,我是不是漏掉了什么?

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