C# 中的数组和字典问题

一 . 数组(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";

你可能感兴趣的:(.Net)