List of Lists 我常忘記用法,今天來筆記
參考其他人寫得不錯,源自於此,我來筆記筆記
List<List<string>> myList = new List<List<string>>();
myList.Add(new List<string> { "a", "b" });
myList.Add(new List<string> { "c", "d", "e" });
myList.Add(new List<string> { "f", "g", "h","i" });
foreach (List<string> subList in myList)
{
foreach (string item in subList)
{
Console.WriteLine(item);
}
}
public class CustomerListList : List<CustomerList> { }
public class CustomerList : List<Customer> { }
//class也可以變 List 真好用
public class Customer
{
public int ID { get; set; }
public string SomethingWithText { get; set; }
}
private List<List<int> > mylist = new List<List<int> >();
List<int> sublist = new List<int>();
sublist.Add(1);
sublist.Add(2);
mylist.Add(sublist);
int a = mylist[0][1];// 則 a=2
@copyright MRcodingRoom
觀看更多文章請點MRcoding筆記
觀看更多文章請點MRcoding筆記