c# GroupBy的动态拼接_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > c# GroupBy的动态拼接

c# GroupBy的动态拼接

 2017/12/4 13:15:17  web-sec  程序员俱乐部  我要评论(0)
  • 摘要:publicclassPerson{publicstringFirstName{set;get;}publicstringLastName{set;get;}publicPerson(){}publicPerson(stringfirstName,stringlastName){FirstName=firstName;LastName=lastName;}}List<Person>personList=newList<Person>();personList.Add
  • 标签:C#
public class Person
{
    public string FirstName{set;get;}
    public string LastName{set;get;}

    public Person(){}

    public Person(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
}

List<Person> personList=new List<Person>();
personList.Add(new Person() { FirstName = "Mickey", LastName = "Mouse" });
personList.Add(new Person() { FirstName = "Mickey", LastName = "Mouse" });
personList.Add(new Person() { FirstName = "zhang", LastName = "san" });


string columnName="FirstName";
var dics=personList.GroupBy(x => GetPropertyValue(x, columnName)).ToDictionary(x=>x.Key,x=>x.Count());
foreach(var dic in dics)
{
    textBox1.AppendText(string.Format("{0},{1}\r\n",dic.Key,dic.Value));
}

 

上一篇: 外媒:法拉第未来“到了生命最后一刻” 下一篇: 没有下一篇了!
发表评论
用户名: 匿名