“非泛型类型‘System.Web.UI.Pair’”是什么意思?不能与类型参数一起使用”意思是?
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
{
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
}
使用这个 Excel Library 从 .NET 中创建一个 Excel 文件
我正在 标题中提到的警告。有什么想法吗?
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
{
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
}
I am working on creating a excel file from within .NET, using this Excel Library
I am getting the warning mentioned in the title. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅供将来参考和理解,错误消息:
The non-generic type ''不能与类型参数一起使用
被替换为某些类,表明在您的代码中您正在尝试使用非通用类以通用方式。更具体地说,您正在使用一些与该类型不兼容的语法,在本例中为 <> “Pair”类型上的通用大括号。
典型地解决问题
如果类型与您应该创建的预期类型不同使用使用别名来指向到正确的类型 命名空间 ie< /p>
如果类型符合预期,请确保它是通用的,如果不是,您可以将其修改为通用,如果您有权限/访问这样做,或者您可以选择/创建更适合您的目的的不同类型。
Just for future reference, and understanding, the error message:
The non-generic type '' cannot be used with type arguments
is replaced with some class, indicates that within your code you are attempting to make use of a non-generic class in a generic way. More specifically you are using some syntax which is incompatible with that type, in this case the <> generic braces on the type "Pair".
To typically solve the problem
If the type is different to the expected type you should make use of a using alias to point to the correct type namespace i.e.
If the type is as expected ensure that it is generic, if not you can either modify it to be generic, if you have permission/access to do so, or you could select/create a different type which is more suitable for your purpose.
这意味着上面代码中的
Pair
引用的是System.Web.UI.Pair
而不是其他一些“pair”类,例如System.Collections.Generic .KeyValuePair
(这是通用的)。根据上面的代码要实例化的
Pair
,使用类似的方法来解决问题(此示例假设您确实想使用
MyNamespace.Pair
)。更新:
在你的情况下,确切的解决方案似乎是
It means that
Pair
in the code above is referring toSystem.Web.UI.Pair
instead of some other "pair" class such asSystem.Collections.Generic.KeyValuePair
(which is generic).Depending on which
Pair
the above code was meant to instantiate, use something liketo resolve the issue (this example assumes you really want to use
MyNamespace.Pair
).Update:
It seems that in your case the exact solution is
因为MSDN对Pair的定义是:
不存在包含
Pair
的定义。如果还有另一个 Pair 类,您需要在“using”子句中包含该名称空间。Because MSDN provides the Pair definition as:
There is not a definition that includes
Pair<T1, T2>
. If there is another Pair class, you need to include that namespace in your 'using' clause.