當前位置:成語大全網 - 書法字典 - 字典和收藏的例子

字典和收藏的例子

列表& ltint & gtlist =新列表& ltint & gt();

list . add(1);

list . add(2);

list . add(3);

foreach(列表中的int i)

{

//i是列表中的值

}

詞典& ltint,int & gtdic =新詞典& ltint,int & gt();

DIC . add(1,1);

DIC . add(2,2);

DIC . add(3.3);

遍歷字典

foreach(DIC . keys中的int i)

{

...//i是字典的關鍵字。

int m = DIC【I】;//取value的值。

}

foreach(DIC . values中的int j)

{

...// j是字典的值。

}

//生成帶列表的詞典

詞典& ltint,int & gtdic =新詞典& ltint,int & gt();

foreach(int m in list)//list使用最上面的壹個。

{

如果(!DIC . contain keys(m))

DIC . add(m,m);

}