2012-07-05 31 views
0

我有一个属性列表。我想为同一页面中的多个元素添加这些PropertiesCollections。这就是说,是否有可能在c#中添加2维列表?

[0] => List 
     ([0] => ID 
     [1] => Name 
     [2] => Add 
     [3] => PhoneNo 
     [4] => City) 
[1] => List 
    (And so on.... 


internal class PropertiesCollection : List<Properties> 
{ 
} 

internal class Properties 
{ 
} 

PropertiesCollection collection = new PropertiesCollection(); 

我如何能实现

Something[0,collection[0]] 
Something[0,collection[1]] 
Something[1,collection[0]] 
Something[1,collection[1]] ? 
+0

就像一个多维数组? – Jodrell

+0

你不能使用PropertiesCollection列表吗? –

回答

2

我相信你能做到列表

List<List<string>> list=new List<List<string>>(); 

然后列表来访问,你可以做这样的事情单个元素:

List<string> list=listlist[0]; 
     int i=list[0]; 

或者我们E中的foreach循环等

+0

如何根据索引获取它? – Devi

+0

对不起花了很长时间回复,检查编辑 – Matt

1

您可以使用“列表,做你想做

private enum Property { ID = 0, Name, Add, PhoneNo, City }; 
string[] details = new string[5] { "1", "Frank Butcher". "Y", 
            "02087891256", "London (Albert Square)" }; 
List<string[]> propertyList = new List<string[]>(); 
propertyList.Add(details); 

获得弗兰克肉店名称将然后像

string franksName = propertyList[0][(int)Property.Name]; 

做我希望这可以帮助什么。

+0

这可能是旧的,但经过两天的headbanging,看着这么多关于数组,列表和多维的文章,你的例子对我的需求是完美的 –

0

您可以使用:

List<PropertiesCollection> propColl = new List<PropertiesCollection>(); 
PropertiesCollection coll = new PropertiesCollection(); 
coll.Add(new Properties(some parameters)); 
coll.Add(new Properties(some parameters)); 
propColl.Add(coll); 
propColl[0][0]; 
相关问题