所以我有一个阵列进入酒店信息,我需要的一件是每个酒店的位置,所以我可以将其发送到另一种方法.所以我有我的第一个foreach设置,但现在我想知道如何将位置上的所有数据收集到字符串数组中,以便我可以在读完所有酒店后发送出去.有人可以帮忙,谢谢.
// API call to get the info
ContentAPI.BasicHotelMedia[] rawData = DataHelper.NewContentAPI().GetBasicHotelMedia(ProductCode, ProductYear, SiteBrand);
//setting up the datatable
DataTable dtHotels = InitHotelTable();
//set my variables
foreach (ContentAPI.BasicHotelMedia item in rawData)
{
DataRow dr = dtHotels.NewRow();
dr["HotelCode"] = item.BasicHotelCode;
dr["HotelDescription"] = item.BasicDescription;
dr["WiFi"] = item.HasWifi;
// This is the variable that i need set in the string array so i can send into another method
dr["SellingLocation"] = item.BasicSellingLocation;
// Add other raw data
// Get other info about the hotel
GetHotelMedia(item.BasicHotelCode, ProductYear, item.HasWifi, ref dr);
dtHotels.Rows.Add(dr.ItemArray);
}
Run Code Online (Sandbox Code Playgroud)
我建议使用List而不是初始化字符串[].他们只是更容易合作.喜欢这个:
var locations = new List<string>();
foreach (ContentAPI.BasicHotelMedia item in rawData)
{
...
locations.Add(item.BasicSellingLocation);
}
OtherMethod(locations.ToArray());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
196 次 |
| 最近记录: |