【发布时间】:2017-09-25 06:50:50
【问题描述】:
我想转换列表中的输出,因为 web 服务中的方法调用返回列表中的项目,这里它返回数组中。
catalogueItems = dataService.GetCatalogItemsFromFile(fileFullPath);
我需要将此dataService.GetCatalogItemsFromFile(fileFullPath) 转换为列表。我该怎么做?
【问题讨论】:
我想转换列表中的输出,因为 web 服务中的方法调用返回列表中的项目,这里它返回数组中。
catalogueItems = dataService.GetCatalogItemsFromFile(fileFullPath);
我需要将此dataService.GetCatalogItemsFromFile(fileFullPath) 转换为列表。我该怎么做?
【问题讨论】:
方法有很多,这一种是不知道类型的:
var list = new[] { dataService.GetCatalogItemsFromFile(fileFullPath) }.ToList()
如果你知道类型,那就更好了:
var list = new List<YourType>{ dataService.GetCatalogItemsFromFile(fileFullPath) };
【讨论】: