//普通一点就是
List<List<string>> allTypes = new List<List<string>>();
//animals :
allTypes.add(new List<string>(){ "Cat", "Dog" });
//vegetables :
allTypes.add(new List<string>(){ "Cabbage", "Tomato" });
//fruits :
allTypes.add(new List<string>(){ "Apple", "Banana" });
//这样虽然可以但是有问题 因为虽然都在allTypes里,切不知道Cat是属于animals还是属于fruits
//所以声明一个类
public class Species {
public string TypeName {get; set; }
public List<string> Types { get; set;}
}
List<Species > allTypes = new List<Species >();
//animals :
allTypes.add( new Species (){
TypeName = "animals",
Types = new List<string>(){ "Cat", "Dog" })
}
//vegetables :
allTypes.add( new Species (){
TypeName = "vegetables ",
Types = new List<string>(){ "Cabbage", "Tomato" })
}
//fruits :
allTypes.add( new Species (){
TypeName = "fruits ",
Types = new List<string>(){ "Apple", "Banana" })
}
温馨提示:答案为网友推荐,仅供参考