2013-04-21 123 views
-4

下面是我的代码给出了一个错误: 无法隐式转换类型“System.Collections.Generic.List”到“字符串[]'无法隐式转换类型“System.Collections.Generic.List <string[]>”到“字符串[]”

我试了好几次来解决这个错误。但我没有这样做。 ,如果任何机构可以建议什么可能是解决..谢谢:)

public GetContentResponse GetContent(abcServiceClient client, QueryPresentationElementIDsResponse querypresentationelementresponse) 
     { 
      GetContentRequest GetContentRequest = new GetContentRequest(); 
      GetContentResponse contentresponse = new GetContentResponse(); 
      querypresentationelementresponse = presentationElementId(client); 
      List<string[]> chunks = new List<string[]>(); 
      for (int i = 0; i < querypresentationelementresponse.IDs.Length; i += 25) 
      { 
       chunks.Add(querypresentationelementresponse.IDs.Skip(i).Take(25).ToArray()); 
       contentresponse = client.GetContent(new GetContentRequest() 
       { 
        IDs = chunks // here i get this error 
       }); 
      } 

      return contentresponse; 
     } 

回答

8

你试图列表分配给一个字符串数组。将列表转换为数组。 由于您尚未指定错误的确切位置,我想这是您分配IDs变量时的情况。

下面的代码将解决这个问题:

public GetContentResponse GetContent(abcServiceClient client, QueryPresentationElementIDsResponse querypresentationelementresponse) 
     { 
      GetContentRequest GetContentRequest = new GetContentRequest(); 
      GetContentResponse contentresponse = new GetContentResponse(); 
      querypresentationelementresponse = presentationElementId(client); 
      List<string> chunks = new List<string>(); 
      for (int i = 0; i < querypresentationelementresponse.IDs.Length; i += 25) 
      { 
       chunks.AddRange(querypresentationelementresponse.IDs.Skip(i).Take(25)); 
       contentresponse = client.GetContent(new GetContentRequest() 
       { 
        IDs = chunks.ToArray() 
       }); 
      } 

      return contentresponse; 
     } 
+0

我也做了同样的事情..但这并没有帮助我。 如果您建议这样做,我仍然可以再试一次。 :) 非常感谢。 – 2013-04-21 21:56:33

+0

你在哪一行得到错误? – Kenneth 2013-04-21 21:57:06

+0

按照您所说的做完后显示的错误。 不能隐式地将类型'string [] []'转换为'string []' – 2013-04-21 21:58:30

1

我不知道是什么类型ID还是什么行给出这样的错误,但如果要我猜,我认为它IDs = chunks

这听起来像你试图将列表转换为字符串数组。你需要使用一个方法来使用toArray()进行转换。

编辑:好的,你有一个字符串数组的数组。您需要用以下方法获取正确的数据:

IDs = Chunks.ToArray()[index] 

其中index是正确的数组。不是很熟悉你正在使用的库,所以我不能详细说明。但是,要大胆猜测,请尝试使用i代替index

+1

爆炸,肯尼思,你打我提交按钮:P。 – 2013-04-21 21:57:11

+0

Chris还有机会。我敢打赌'ID'是'string []','chunks.ToArray()'会返回一个'string [] []'。 – 2013-04-21 22:00:58

+0

但是,这个解决方案并没有帮助,虽然:p 另一个尝试可能会给你赢:D – 2013-04-21 22:01:34

相关问题