简体   繁体   English

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

[英]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;
            }

I am working on creating a excel file from within .NET, using this Excel Library我正在使用这个Excel 库从 .NET 中创建一个 excel 文件

I am getting the warning mentioned in the title.我收到标题中提到的警告。 Any ideas?有任何想法吗?

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).这意味着上面代码中的Pair指的System.Web.UI.Pair而不是其他一些“对” class 例如System.Collections.Generic.KeyValuePair

Depending on which Pair the above code was meant to instantiate, use something like根据上面的代码要实例化的Pair ,使用类似的东西

using Pair = MyNamespace.Pair;

to resolve the issue (this example assumes you really want to use MyNamespace.Pair ).解决问题(此示例假设您确实想要使用MyNamespace.Pair )。

Update:更新:

It seems that in your case the exact solution is看来,在你的情况下,确切的解决方案是

using Pair = QiHe.CodeLib.Pair;

Just for future reference, and understanding, the error message:仅供将来参考和理解,错误消息:

The non-generic type '' cannot be used with type arguments非泛型类型 '' 不能与类型 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.被一些 class 替换,表示在您的代码中,您正试图以通用方式使用非通用 class More specifically you are using some syntax which is incompatible with that type, in this case the <> generic braces on the type "Pair".更具体地说,您正在使用一些与该类型不兼容的语法,在这种情况下,“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<") (这应该找到它们:Ctrl + F >“SomeClass<”)
  • Ensure that the type is as expected (F12 on the type should take you to its declaration)确保类型符合预期(类型上的 F12 应将您带到其声明)
  • If the type is different to the expected type you should make use of a using alias to point to the correct type namespace ie如果类型与预期类型不同,则应使用using 别名来指向正确的类型命名空间,即

    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或者,您可以将类型的使用修改为非泛型

Because MSDN provides the Pair definition as:因为 MSDN 提供 Pair 定义为:

[SerializableAttribute]
public sealed class Pair

There is not a definition that includes Pair<T1, T2> .没有包含Pair<T1, T2>的定义。 If there is another Pair class, you need to include that namespace in your 'using' clause.如果还有另一对 class,则需要在“使用”子句中包含该命名空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在这种情况下,非泛型方法不能与类型参数一起使用是什么意思? - What does The non-generic method cannot be used with type arguments mean in this context? 非通用类型&#39;IdentityUser&#39;不能与类型参数一起使用 - The non-generic type 'IdentityUser' cannot be used with type arguments 意外的“非泛型类型不能与类型参数一起使用”? - An unexpected “The non-generic type cannot be used with the type arguments”? 错误非泛型类型“…”不能与类型参数一起使用 - Error The non-generic type '…' cannot be used with type arguments 错误:不能使用非通用类型&#39;GenericTypeIndicator&#39;的类型参数 - Error: The non-generic type 'GenericTypeIndicator' cannot be used type arguments 非泛型类型&#39;System.Collections.ArrayList&#39;不能与类型参数一起使用 - The non-generic type 'System.Collections.ArrayList' cannot be used with type arguments 非泛型类型'System.Collections.IEnumerable'不能与类型参数一起使用 - The non-generic type 'System.Collections.IEnumerable' cannot be used with type arguments 非通用方法“字典 <Type, Type> .Add(Type,Type)&#39;不能与类型参数一起使用 - The non-generic method 'Dictionary<Type, Type>.Add(Type, Type)' cannot be used with type arguments 不知道如何解决“非泛型类型 'ArrayList' 不能与类型参数一起使用”? - Don't know how to fix "The non-generic type 'ArrayList' cannot be used with type arguments"? “非泛型方法‘IServiceProvider.GetService(Type)’不能与类型参数一起使用 - "The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM