不規則Array

object[][] obj = new object[2][];//第一個維度要給長度(可以給零)

obj[0] = new object[] { "a", "b" };

obj[1] = new object[] { "c", "d" };


List

List<object[]> list = new List<object[]>();

list.Add(new object[]{"a","b"});

object[][] obj = new object[2][];

obj[0] = new object[] { "a", "b" };

obj[1] = new object[] { "c", "d" };

list.AddRange(obj);//將陣列放入List中

//List or Dictionary 計算長度不是Length, 而是Count

//List可以轉成Array: list.ToArray();

//List有sort方法

Dictionary

Dictionary<string, int> dic = new Dictionary<string, int>();

dic.Add("A", 1);

dic.Add("B", 2);

//dic["A"]為1, dic["B"]為2

//用foreach取得Dictionary的值

foreach (KeyValuePair<string, int> val in dic)

{

    string str = val.Key;

    int num = val.Value;

}

arrow
arrow
    全站熱搜

    Big Bear 發表在 痞客邦 留言(0) 人氣()