缺少装配参考?
我有以下示例方法:
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; }
}
}
这会导致程序集引用错误。 (已添加使用 System.Collections.Generic)
I have 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 in an assembly reference error. (using System.Collections.Generic has been already added)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更好取决于您需要使用它做什么。如果您要传递此客户端来填充列表框,那么我更喜欢 json。但是,如果要在服务器端使用它,我会坚持使用 .Net 对象。
作为旁注,为了消除连接字符串来存储数据的愿望,我将定义一个包含城市和邮政编码的类型,如下所示:
然后使用这些的数组(或列表):
然后将列表返回为如上所述。如果您需要返回一个数组,您可以这样做:
return myList.ToArray();
,这将是
MyAddressInfo[]
的返回类型@Thomas:
根据您的评论,您的方法声明应如下所示:
当您像这样编译它时,您看到的其他错误是什么?
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:
and then use an array (or List) of these:
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:
What are the other errors that you see when you compile it like this?
为什么不从方法中返回
KeyValuePair
(或更合适的数据结构)列表?返回一个由城市名称和邮政编码组成的连接字符串是一种混乱的解决方案,并且通过返回一组连接值也不会变得更整洁。
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.