Missing assembly reference?

I have the following example method:

namespace Postcode_webservice { public class 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 leads to an assembly reference error. (using System.Collections.Generic already added)

+4
source share
2 answers

Better depends on what you need to use. If you pass this client part to populate the list, then I would prefer json. However, if it will be used on the server side, I will stick with .Net objects.

As a side note, to eliminate the desire to combine rows for data storage, I would define a type that contains both the city and the postal code, for example:

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

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

 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 will be the return type MyAddressInfo[]

@Thomas: For your comment, the declaration of your method should look like this:

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

What are the other errors you see when compiling this type?

+3
source

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

Returning a single concatenated string of city names and zip codes is a kind of messy solution, and it is not going to get any operand by returning an array of concatenated values.

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

Source: https://habr.com/ru/post/1340643/


All Articles