不显示属性列表数据

本文关键字:数据 列表 属性 显示 | 更新日期: 2023-09-27 18:36:28

网关.cs页面

public class gatewayConnectionPropertyData
{
public string url { get; set; }
public int type { get; set; }
public string service_desc { get; set; }
}
protected void btnAddEdit_Click(object sender, EventArgs e) 
{
gatewayConnectionPropertyData proposal = new gatewayConnectionPropertyData();
proposal.url = "/testproposal.xml";
proposal.type = 13;
proposal.service_desc = "proposal";
gatewayConnectionPropertyData utility = new gatewayConnectionPropertyData();
proposal.url = "/testUtulity.xml";
proposal.type = 12;
proposal.service_desc = "utility";
gatewayConnectionPropertyData intelligence = new gatewayConnectionPropertyData();
proposal.url = "/testinteligence.xml";
proposal.type = 53;
proposal.service_desc = "intelligence";

List<gatewayConnectionPropertyData> mydataList = new List<gatewayConnectionPropertyData>(); 
gatewayConnectionPropertyDataList.Add(proposal); 
gatewayConnectionPropertyDataList.Add(utility); 
gatewayConnectionPropertyDataList.Add(intelligence); 
}

mydataList 总是计数 3,但只出现 last 添加的项目,我看不到所有数据,我错过了我需要更改的内容。如果有任何意见,我可以申请更好的解决方案,以创建属性列表模型

谢谢。

不显示属性列表数据

首先,

您要在gatewayConnectionPropertyDataList中添加项目(我不确定它是什么),但是如果您期望mydataList中的数据,则只需要添加此变量。此外,您可以像这样使用collection initializers:-

List<gatewayConnectionPropertyData> mydataList = 
                                new List<gatewayConnectionPropertyData>
{
  new gatewayConnectionPropertyData { url = "/testproposal.xml", type = 13, 
                                             service_desc = "proposal" },
  new gatewayConnectionPropertyData { url = "/testUtulity.xml", type = 12, 
                                             service_desc = "utility" },
  new gatewayConnectionPropertyData { url = "/testinteligence.xml", type = 53,
                                             service_desc = "intelligence" },
};