C# 中的陣列和字典問題
阿新 • • 發佈:2018-12-26
一 . 陣列(List)
1 . 建立陣列
//建立陣列
List<string> list = new List<string>(); // Example List
2 .向陣列中新增元素值
list.Add(videoBgImgURL = videoBgImgURL);// Contains: spaniel
list.Add(videoUrl = videoUrl);// Contains: spaniel, beagle
list.Insert(1, videoPlayImgURL = videoPlayImgURL);
3 . 遍歷獲取值
foreach (string s in list)
{
Console.WriteLine(s);
}
二. 字典(Dictionary)
1 .建立字典
//建立字典
Dictionary<string, string> dict = new Dictionary<string, string>();
2 . 向字典中新增元素值
//新增字典的元素
dict.Add("videoBgImgURL" , videoBgImgURL);
dict.Add("videoUrl", videoUrl);
dict.Add("videoPlayImgURL", videoPlayImgURL);
3 .向字典中取值
//取值/賦值
string val = d["key1"];
d["key1"] = "new value";