![](/img/trans.png)
[英]What does The non-generic method cannot be used with type arguments mean in this context?
[英]What does “The non-generic type 'System.Web.UI.Pair' cannot be used with type arguments” mean?
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
{
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
}
我正在使用这个Excel 库从 .NET 中创建一个 excel 文件
我收到标题中提到的警告。 有任何想法吗?
这意味着上面代码中的Pair
指的是System.Web.UI.Pair
而不是其他一些“对” class 例如System.Collections.Generic.KeyValuePair
根据上面的代码要实例化的Pair
,使用类似的东西
using Pair = MyNamespace.Pair;
解决问题(此示例假设您确实想要使用MyNamespace.Pair
)。
更新:
看来,在你的情况下,确切的解决方案是
using Pair = QiHe.CodeLib.Pair;
仅供将来参考和理解,错误消息:
非泛型类型 '' 不能与类型 arguments 一起使用
被一些 class 替换,表示在您的代码中,您正试图以通用方式使用非通用 class 。 更具体地说,您正在使用一些与该类型不兼容的语法,在这种情况下,“Pair”类型上的 <> 通用大括号。
典型地解决问题
因为 MSDN 提供 Pair 定义为:
[SerializableAttribute]
public sealed class Pair
没有包含Pair<T1, T2>
的定义。 如果还有另一对 class,则需要在“使用”子句中包含该命名空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.