“非泛型类型‘System.Web.UI.Pair’”是什么意思?不能与类型参数一起使用”意思是?

发布于 2024-11-04 19:03:57 字数 352 浏览 2 评论 0原文

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半山落雨半山空 2024-11-11 19:03:57

仅供将来参考和理解,错误消息:

The non-generic type ''不能与类型参数一起使用

被替换为某些类,表明在您的代码中您正在尝试使用非通用类以通用方式。更具体地说,您正在使用一些与该类型不兼容的语法,在本例中为 <> “Pair”类型上的通用大括号。

典型地解决问题

  • 确定文件中使用的类型,特别是其以通用方式的使用。 (这应该找到它们:Ctrl + F >“SomeClass<”)
  • 确保类型符合预期(类型上的 F12 应该将您带到其声明)
  • 如果类型与您应该创建的预期类型不同使用使用别名来指向到正确的类型 命名空间 ie< /p>

    using Pair = Excellent.Qualified.Namespace.Of.Pair;
    
  • 如果类型符合预期,请确保它是通用的,如果不是,您可以将其修改为通用,如果您有权限/访问这样做,或者您可以选择/创建更适合您的目的的不同类型。

  • 或者,您可以将类型的使用修改为非泛型

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

  • Identify the types use within the file, specifically its use in a generic way. (This should find them: Ctrl + F > "SomeClass<")
  • Ensure that the type is as expected (F12 on the type should take you to its declaration)
  • 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.

    using Pair = Fully.Qualified.Namespace.Of.Pair;
    
  • 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.

  • Alternativly you could modify your use of the type to be non-generic
瘫痪情歌 2024-11-11 19:03:57

这意味着上面代码中的 Pair 引用的是 System.Web.UI.Pair 而不是其他一些“pair”类,例如 System.Collections.Generic .KeyValuePair(这是通用的)。

根据上面的代码要实例化的 Pair,使用类似的方法

using Pair = MyNamespace.Pair;

来解决问题(此示例假设您确实想使用 MyNamespace.Pair)。

更新:

在你的情况下,确切的解决方案似乎是

using Pair = QiHe.CodeLib.Pair;

It means that Pair in the code above is referring to System.Web.UI.Pair instead of some other "pair" class such as System.Collections.Generic.KeyValuePair (which is generic).

Depending on which Pair the above code was meant to instantiate, use something like

using Pair = MyNamespace.Pair;

to resolve the issue (this example assumes you really want to use MyNamespace.Pair).

Update:

It seems that in your case the exact solution is

using Pair = QiHe.CodeLib.Pair;
旧人九事 2024-11-11 19:03:57

因为MSDN对Pair的定义是:

[SerializableAttribute]
public sealed class Pair

不存在包含Pair的定义。如果还有另一个 Pair 类,您需要在“using”子句中包含该名称空间。

Because MSDN provides the Pair definition as:

[SerializableAttribute]
public sealed class Pair

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文