当前位置:   article > 正文

ASP.NET中Dictionary如何转换为list_dictory转化成list

dictory转化成list

一、创建List的时候,将Dictionary的Value值作为参数

 

  1. Dictionary<int, Person> dic = new Dictionary<int, Person>();
  2. List<Person> pList = new List<Person>(dic.Values);



二、用Dictionary对象自带的ToList方法


 

  1. Dictionary<int, Person> dic = new Dictionary<int, Person>();
  2. List<Person> pList=new List<Person>();
  3. pList = dic.Values.ToList<Person>();



三、建立List,循环Dictionary逐个赋值


  1. Dictionary<int, Person> dic = new Dictionary<int, Person>();
  2. List<Person> pList=new List<Person>();
  3. foreach (var item in dic)
  4. {
  5. pList.Add(item.Value);
  6. }




四、创建List后,调用List.AddRange方法


  1. Dictionary<int, Person> dic = new Dictionary<int, Person>();
  2. List<Person> pList=new List<Person>();
  3. pList.AddRange(dic.Values);

 


五、通过Linq查询,得到结果后调用ToList方法


  1. Dictionary<int, Person> dic = new Dictionary<int, Person>();
  2. List<Person> pList=new List<Person>();
  3. pList = (from temp in dic select temp.Value).ToList();


文章转载自:ASP.NET中Dictionary如何转换为list  http://www.studyofnet.com/news/1206.html


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/100554
推荐阅读
相关标签
  

闽ICP备14008679号