将ArrayOfString转换为C#for Windows Phone 7 </string>中的List <string>

时间:2013-08-22 01:26:42

标签: c# windows-phone-7

我有一个错误“无法隐式转换类型”CorrespondingBall.MyCloudService.ArrayOfString'到'System.Collections.Generic.List“。有谁知道如何解决它?我已阅读Convert array of strings to List<string>,但我不理解并实施它。我的代码如下。

ServiceSoapClient client = new ServiceSoapClient();

List<string> objectiveList = new List<string>();

client.getObjectiveCompleted += new EventHandler<getObjectiveCompletedEventArgs>(getObjectiveCompletedHandler);
client.getObjectiveAsync();

我收到了

的错误
private void getObjectiveCompletedHandler(object sender, getObjectiveCompletedEventArgs e)
    {
        objectiveList = e.Result;
    }

2 个答案:

答案 0 :(得分:4)

如果ArrayOfString确实是array种类型的基本string,您可以执行以下操作:

    string[] names = { "John", "Doe" };

    List<string> namesList = new List<string>(names);

    // OR

    List<string> namesList2 = new List<string>();

    foreach (string name in names)
    {
        namesList2.Add(name);
    }

答案 1 :(得分:2)

假设e.Result是一个字符串数组,你可以这样做

private void getObjectiveCompletedHandler(object sender, getObjectiveCompletedEventArgs e)
    {
      List<string> namesList = new List<string>();

      foreach (string name in e.Result)
       {
        namesList.Add(name);
       }
    }