2013-02-15 159 views
0

我有这样的代码:参数类型是不能分配给参数类型

List<Pair<string, string>> docs = new List<Pair<string, string>>(); 
iErr = ftpconnect.ListAllDocuments(docs, build.BuildId.ToString()); 
ListAllDocuments的

界面原型是:

Int32 ListAllDocuments(List<Pair<string, string>> DocList, string Path); 

我得到一个错误

错误21: 'OperatorPanelWrapper.FtpTransportLibWrapper.ListAllDocuments(System.Collections.Generic.List < Operator)的最佳重载方法匹配Panel.Pair < string,string >>,string)'有一些无效参数

为什么我得到这个错误?

+0

你的'Pair'类是什么? – Habib 2013-02-15 09:53:40

+0

这是我的模板班,通常对 – user2071019 2013-02-15 09:57:55

+0

其他错误呢?通常你会得到第二个错误,说明这些类型有什么问题。 – CodesInChaos 2013-02-15 10:18:04

回答

1

尝试

List<OperatorPanel.Pair<string, string>> docs = new List<OperatorPanel.Pair<string, string>>(); 
+0

我做过了,但没有必要编写OperatorPanel。 – user2071019 2013-02-15 09:56:59

+0

它是唯一的编译错误吗? – hoang 2013-02-15 10:12:49

2

在您发布的第一个代码(new List<Pair<string, string>>()),尝试把你的光标在Pair,看看那里的Visual Studio认为它被定义。它应该显示OperatorPanel.Pair<T1, T2>。如果它显示在其他地方定义的Pair类型的名称(或错误),那么您的类型是错误的。

有几种可能性:

  • 你有地方规定(也许是无意的)另一个Pair类,它是指错了。
  • 您错过了顶部的using directive以指定编译器应该在哪个命名空间中寻找您的Pair
  • 您有一个不同名称空间的using指令,其中包含Pair which is not the one you want(例如using System.Web.UI)。
  • 您缺少对定义您的Pair的DLL的引用。
  • List<T>基准是某种错误的(也许你定义自己?)
  • (不太可能)你自己定义了ToString上任何BuildId是,不返回string

基本上,检查所有类型。首先在调用代码中:List是指System.Collections.Generic.List<T>Pair是指通用OperatorPanel.Pair<T1, T2> ...

+0

一切都可以,那是OperatorPanel.Pair – user2071019 2013-02-15 10:02:06

+0

@ user2071019:检查你的其他类型。 – Virtlink 2013-02-15 10:11:07

+0

@ user2071019 - 您的评论听起来像Virtlink关于'using'指令的第二点是解决方案。你应该把这个标记为你的答案。 – 2016-05-26 08:22:03

相关问题