开发者

Missing assembly reference ?

I have following example method:

namespace Postcode_webservice
{    
    public cl开发者_如何学运维ass Business
    {
      public string getBusinessDossierno(string KVKnr)
        {
              StringBuilder resultaat = new StringBuilder();
              result = myserviceBusiness.businessGetDossierV3(KVKnr);

              string city = result.results[0].CorrespondenceCity;
              string postcode = result.results[0].CorrespondencePostcode;

              resultaat.Append(city);
              resultaat.Append(postcode);
              return resultaat.ToString();
        }
    }

    public class BusinessInfo
    {
    public string City { get; set; }
    public string PostCode { get; set; }
    public string bedrijfsNaam { get; set; }
    public string adres { get; set; }
    public int huisnr { get; set; }
    }
}

This result in an assembly reference error. (using System.Collections.Generic has been already added)


Better depends on what you need to use it for. If you are passing this client-side to populate the listbox, then I would prefer json. However, if it is to be used server-side, I would stick to .Net objects.

As a side note, to eliminate the desire to concatenate strings to store data, I would define a type that contains both city and postal code, like this:

public class MyAddressInfo
{
    public string City { get; set; }
    public string PostCode {get; set; }
}

and then use an array (or List) of these:

List<MyAddressInfo> myList = new List<MyAddressInfo>();
foreach(var res in result.results)
{
    myList.Add(new MyAddressInfo
    {
        City = res.CorrespondenceCity,
        PostCode = res.CorrespondencePostcode
    });
}

And then return the list as described above. If you need to return an array, you can do this:

return myList.ToArray();

which would be a return type of MyAddressInfo[]

@Thomas: Per your comment, your method declaration should look like this:

public MyAddressInfo[] getBusinessDossierno(string KVKnr)
{
   // etc.
   return myList.ToArray();
}

What are the other errors that you see when you compile it like this?


Why not return a list of KeyValuePair<string, string> (or some more appropriate data structure) out of the method?

Returning one conjoined string of city names and zip codes is kind of a messy solution and it's not going to get any neater by returning an array of conjoined values.

return result.results.Select(r => new KeyValuePair<string, string>(r. CorrespondenceCity, r.CorrespondencePostcode));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜