示例#1
0
        public static void pgdoj(PersonList per)
        {
            var b = from a in per
                    where !a.Name.Contains("欧阳")
                    group a by a.Name.Substring(0, 1)
                    into box
                    select new { box.Key, sum = box.Count() };

            foreach (var i in b)
            {
                Console.WriteLine("姓:{0},人数:{1}", i.Key, i.sum);
            }



            var name = from a in per
                       where a.Name.Contains("欧阳")
                       group a by a.Name.Substring(0, 2)
                       into box
                       select new { box.Key, sum = box.Count() };

            foreach (var i in name)
            {
                Console.WriteLine("姓:{0},人数:{1}", i.Key, i.sum);
            }
            Console.Read();
        }
示例#2
0
        public static List <string> GetProvincesGroupBy(PersonList persons)
        {
            var result = new List <string>();

            foreach (var item in persons.GroupBy(x => x.Province))
            {
                result.Add(item.Key);
            }
            return(result);
        }
示例#3
0
        public static List <string> GetProvinces(PersonList persons)
        {
            var result = new List <string>();

            foreach (var item in persons)
            {
                if (!result.Contains(item.Province))
                {
                    result.Add(item.Province);
                }
            }
            return(result);
        }
示例#4
0
        public static List <PersonsInProvince> GetProvincesPersons(PersonList persons)
        {
            var result = new List <PersonsInProvince>();

            foreach (var item in persons.GroupBy(x => x.Province))
            {
                var data = new PersonsInProvince
                {
                    ProvinceName = item.Key,
                    Amount       = item.Count()
                };
                result.Add(data);
            }
            return(result);
        }
示例#5
0
        public static string AverageAge(PersonList persons)
        {
            var result    = "";
            var totalDays = 0;
            var now       = DateTime.Now;

            foreach (var item in persons)
            {
                totalDays = totalDays + Math.Abs(((TimeSpan)(now - item.Birthday)).Days);
            }

            var avgTotaldays = totalDays / persons.Count;
            var avgYears     = avgTotaldays / 365;
            var avgDays      = avgTotaldays - avgYears * 365;

            result = "平均年龄:" + avgYears + "周岁" + "-" + avgDays + "天";
            return(result);
        }
示例#6
0
        public static PersonList InitialPersonList()
        {
            var persons = new PersonList();

            #region 初始化人员数据
            persons.Add(new Person {
                Name = "张小祎", Province = "北京", City = "北京", Sex = true, Birthday = DateTime.Parse("1964-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "李珊柳", Province = "北京", City = "北京", Sex = false, Birthday = DateTime.Parse("1966-02-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "李华语", Province = "河北", City = "石家庄", Sex = true, Birthday = DateTime.Parse("1966-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "黄慧琳", Province = "河北", City = "廊坊", Sex = false, Birthday = DateTime.Parse("1966-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "潘加伟", Province = "河北", City = "唐山", Sex = true, Birthday = DateTime.Parse("1963-10-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "秦小梨", Province = "河北", City = "唐山", Sex = false, Birthday = DateTime.Parse("1966-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "覃晓琳", Province = "河北", City = "石家庄", Sex = true, Birthday = DateTime.Parse("1968-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "韦长英", Province = "广西", City = "柳州", Sex = true, Birthday = DateTime.Parse("1969-03-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "韦大东", Province = "广西", City = "南宁", Sex = true, Birthday = DateTime.Parse("1969-03-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "韦家文", Province = "广西", City = "柳州", Sex = true, Birthday = DateTime.Parse("1969-03-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "黎文新", Province = "广西", City = "柳州", Sex = true, Birthday = DateTime.Parse("1969-03-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "黎子流", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1969-03-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "余卫东", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1969-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "何家宝", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1970-08-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "何欣俊", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1970-08-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "余华亮", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1970-08-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "汤富贵", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1970-08-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "唐富贵", Province = "广东", City = "广州", Sex = true, Birthday = DateTime.Parse("1970-08-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "唐蔚佳", Province = "广东", City = "深圳", Sex = false, Birthday = DateTime.Parse("1964-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "谢显才", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1972-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "解晓东", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1972-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "谢家麟", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1972-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "谢子怡", Province = "广东", City = "深圳", Sex = false, Birthday = DateTime.Parse("1973-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "张建光", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "李振书", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "陈丰州", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "陈卫东", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "陈峰受", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "陈金健", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "韦海波", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "祁宣明", Province = "广东", City = "深圳", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "戚计生", Province = "上海", City = "上海", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "石智生", Province = "广西", City = "柳州", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "苏晓琳", Province = "广西", City = "柳州", Sex = false, Birthday = DateTime.Parse("1989-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "苏振彪", Province = "广西", City = "柳州", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "谭家伟", Province = "广西", City = "柳州", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "谭俊杰", Province = "广西", City = "桂林", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "王定祠", Province = "广西", City = "桂林", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "王金生", Province = "广西", City = "北海", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "王宝军", Province = "广西", City = "钦州", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "吴克标", Province = "广西", City = "防城港", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "吴斌", Province = "江西", City = "南昌", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "游毅峰", Province = "湖南", City = "长沙", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "柳君华", Province = "湖南", City = "长沙", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "刘小薇", Province = "湖南", City = "郴州", Sex = false, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "陈东风", Province = "湖南", City = "衡阳", Sex = true, Birthday = DateTime.Parse("1999-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "欧阳海", Province = "湖南", City = "长沙", Sex = true, Birthday = DateTime.Parse("1985-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "柳三变", Province = "湖南", City = "邵阳", Sex = true, Birthday = DateTime.Parse("1986-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "郭骁", Province = "北京", City = "北京", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "郭家铭", Province = "香港", City = "香港", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "陈兆年", Province = "四川", City = "成都", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "农卫红", Province = "四川", City = "成都", Sex = false, Birthday = DateTime.Parse("2000-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "农志升", Province = "四川", City = "成都", Sex = true, Birthday = DateTime.Parse("1989-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "农小琳", Province = "四川", City = "攀枝花", Sex = true, Birthday = DateTime.Parse("1988-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "徐荣国", Province = "四川", City = "泸州", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "聂小威", Province = "四川", City = "泸州", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "邱福林", Province = "四川", City = "泸州", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "范思坦", Province = "四川", City = "泸州", Sex = true, Birthday = DateTime.Parse("1996-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "邓唯佳", Province = "四川", City = "泸州", Sex = false, Birthday = DateTime.Parse("1998-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "马晓东", Province = "云南", City = "昆明", Sex = true, Birthday = DateTime.Parse("1999-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "魏明翠", Province = "云南", City = "昆明", Sex = false, Birthday = DateTime.Parse("2000-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "尹相杰", Province = "贵州", City = "贵阳", Sex = true, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            persons.Add(new Person {
                Name = "张小祎", Province = "贵州", City = "凯里", Sex = false, Birthday = DateTime.Parse("1993-09-08"), Email = "*****@*****.**"
            });
            #endregion

            return(persons);
        }
示例#7
0
 public PersonEnumerator(PersonList collection)
 {
     _collection = collection;
     curIndex    = -1;
     curPerson   = default(Person);
 }