如何在Visual Basic(ASP)中创建以下关联数组数组?
array(
array('customer' => 'khl', 'city' => 'bune'),
array('customer' => 'Kla', 'value' => 'Swa')
)
答案 0 :(得分:2)
这是一种方法:
var array = new List<Dictionary<string,string>>();
array.Add(new Dictionary<string,string>());
array[0].Add("customer", "khl");
array[0].Add("city", "bune");
array.Add(new Dictionary<string,string>());
array[1].Add("customer", "Kla");
array[1].Add("city", "Swa");
如果您知道参数是以集合形式存在,那么您可以通过将详细信息作为结构来简化:
struct Customer
{
public string Name;
public string City;
}
var array = new List<Customer>();
array.Add(new Customer { Name = "khl", City = "bune" });
array.Add(new Customer { Name = "Kla", City = "Swa" });