3

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;
    }
3
  • I don't know what a CorrespondingBall.MyCloudService.ArrayOfString is, but can you use a foreach and add them to the list one by one? Commented Aug 22, 2013 at 1:29
  • Hi @Jonesy, I am using a web service, MyCloudService and the application name is CorrespondingBall. Commented Aug 22, 2013 at 1:34
  • Are you return List<string> from your service method? or string[]? what is your web service (WCF, ASMX..)? are you adding service reference or web reference? Commented Aug 22, 2013 at 2:49

2 Answers 2

4

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);
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Hi @Inisheer, what if the values are from database?
@LiuJiaHui It doesn't matter the source of the data. More important is how you are retrieving and storing that data in your code. You will need to provide additional code in order to provide a more detailed solution.
2

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);
       }
    }

3 Comments

This is ofchurs depending if e.Result is really returning array. If not then you should change your question to how to return an array from your cloud service
Hi @TheProvost, it is returning a list.
If its returning a list as you say it does. then objectiveList = e.Result; would not have triggered an error. Im sure the problem is with sending the correct object type rather than conversion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.