我想使用Tuple.Create()
创建一个元组签名为Tuple<String,String,Func<String,Control>>
,但是当我这样做的时候;我收到错误:
The type arguments for method 'Tuple.Create<T1,T2,T3>(T1,T2,T3)'
cannot be inferred from the usage. Try specifying the types explicitly.
这是我的代码段:
public List<Tuple<String, String, Func<string,Control>>> Headers { get; set; } = new List<Tuple<String, String, Func<string,Control>>> {
Tuple.Create("Name","Type", TypeControl),
Tuple.Create("Age","TypeAge", AgeControl),
};
public Control TypeControl(string data = ""){
// code returns a Control
}
public Control AgeControl(string data = ""){
// code returns a Control
}
如果没有Tuple.Create()
new Tuple<T1,T2,T3>(T1,T1,T3)
来实现此目的
答案 0 :(得分:1)
您必须通过提供类型参数显式指定最后一个参数的类型:
import aioprocessing
async def producer_handler(websocket):
while True:
message = await inputqueue.coro_get()
await websocket.send(message)
await asyncio.sleep(.1)
inputqueue = aioprocessing.AioQueue()
或传递public List<Tuple<string, string, Func<string, Control>>> Headers { get; set; } = new List<Tuple<string, string, Func<string, Control>>> {
Tuple.Create<string, string, Func<string, Control>>("Name","Type", TypeControl),
Tuple.Create<string, string, Func<string, Control>>("Age","TypeAge", AgeControl)
};
:
Func<string, Control>
有关原因的更多信息:
Why can't C# compiler infer generic-type delegate from function signature?