Abi*_*Ali -5 c# asp.net web-services casting
下面是我的代码,它给出了一个错误: 无法将类型'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;
}
Run Code Online (Sandbox Code Playgroud)
您正在尝试将List分配给字符串数组.将列表转换为数组.由于您没有准确指出错误的位置,我想当您分配ID变量时.
以下代码将解决它:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10234 次 |
| 最近记录: |