C# 中的数组和字典问题

来源:互联网 发布:淘宝按图片搜索 编辑:程序博客网 时间:2024/06/14 18:35

一 . 数组(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";
原创粉丝点击