gpt4 book ai didi

c# - 如何将泛型类型(T)作为参数?

转载 作者:行者123 更新时间:2023-12-03 04:43:05 27 4
gpt4 key购买 nike

我有这个错误:

Severity    Code    Description Project File    Line
Error CS0246 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

在此方法的方法签名上:

 public static void SendMessage(string queuName, T objeto)
{
QueueClient Client =QueueClient.CreateFromConnectionString(connectionString, "Empresa");
BrokeredMessage message = new BrokeredMessage(objeto);
message.ContentType = objeto.GetType().Name;
Client.Send(new BrokeredMessage(message));
}

最佳答案

public static void SendMessage<T>(string queuName, T objeto)
{
QueueClient Client =QueueClient.CreateFromConnectionString(connectionString, "Empresa");
BrokeredMessage message = new BrokeredMessage(objeto);
message.ContentType = objeto.GetType().Name;
Client.Send(new BrokeredMessage(message));
}

关于c# - 如何将泛型类型(T)作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31302356/

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