c# GroupBy的动态拼接


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));
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM