我想将AppGuid
和AppName
添加到循环中的httpResp
列表中,并与运行该循环的当前索引具有相同的索引,以便获得httpResp
列表其中包括AppGuid
和AppName
,我该怎么做?
var data = new List<GetBuildTempClass>();
List<BuildsClass.BuildsRootObject> httpResp = new List<BuildsClass.BuildsRootObject>();
foreach (var app in data)
{
var request = new HttpRequestMessage(HttpMethod.Get, "apps/" + app.AppGuid + "/builds?per_page=200&order_by=updated_at");
var response = await _client_SB.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();
BuildsClass.BuildsRootObject model = JsonConvert.DeserializeObject<BuildsClass.BuildsRootObject>(json);
if (model != null)
{
httpResp.Add(model);
}
}
public partial class GetBuildTempClass
{
public Guid AppGuid { get; set; }
public string AppName { get; set; }
}
public class BuildsClass
{
public class Data
{
public List<string> buildpacks { get; set; }
public string stack { get; set; }
}
public class Lifecycle
{
public string type { get; set; }
public Data data { get; set; }
}
public class App
{
public string href { get; set; }
}
public class Links
{
public App app { get; set; }
}
public class CreatedBy
{
public string guid { get; set; }
public string name { get; set; }
public string email { get; set; }
}
public class Resource
{
public string guid { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public string state { get; set; }
public object error { get; set; }
public Lifecycle lifecycle { get; set; }
public Links links { get; set; }
public CreatedBy created_by { get; set; }
}
public class BuildsRootObject
{
public List<Resource> resources { get; set; }
}
}
答案 0 :(得分:1)
我想你想有一个元组列表
var httpResp = new List<(BuildsClass.BuildsRootObject rootObj,Guid AppGuid,string appName)>();
要添加您的内容
httpResp.Add( (model,Guid.Parse(resource.Guid),resource.AppName));
然后您可以循环访问元组或将其作为单个命名变量访问,也可以通过索引在列表中访问。
var name= httpResp[0].appName;
如果在创建命名元组时知道名称。如果不命名,则会自动生成item1,ite2,...。