Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ArrayOfString to List<string> in C# for Windows Phone 7

I have an error "Cannot implicitly convert type "CorrespondingBall.MyCloudService.ArrayOfString' to 'System.Collections.Generic.List". Does anyone know how can I solved it? I have read up on Convert array of strings to List<string>, but I do not understand and implement it. My codes are below.

ServiceSoapClient client = new ServiceSoapClient();

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

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

I received the error for

private void getObjectiveCompletedHandler(object sender, getObjectiveCompletedEventArgs e)
    {
        objectiveList = e.Result;
    }
like image 577
Liu Jia Hui Avatar asked May 02 '26 13:05

Liu Jia Hui


2 Answers

If ArrayOfString is truly a basic array of string types, you can do the following:

    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);
    }
like image 98
Inisheer Avatar answered May 05 '26 02:05

Inisheer


Supposing e.Result is an array of string you can do it like this

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

      foreach (string name in e.Result)
       {
        namesList.Add(name);
       }
    }
like image 33
TheProvost Avatar answered May 05 '26 04:05

TheProvost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!