列表年龄排序问题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace _34班人数排序
{
    public class Program
    {


        public class boy
        {
            public int age;
            private string name;


            public string Name
            {
                get { return name; }
                set { name = value; }
            }


            public boy(int mage, string name)
            {
                this.age = mage;
                this.name = name;
            }


          
            public string SelfIntroduction()
            {
                string selfIntroduction = String.Format("34班的人是:{0},年龄{1}", name, age);
                return selfIntroduction;
            }


           
            static void Main(string[] args)
            {
                List list1 = new List(4);


                list1.Add(new boy (22,"梦阳"));
                list1.Add(new boy(25, "侯勇"));
                list1.Add(new boy(26, "黄硕"));
                list1.Add(new boy(27, "阿星"));
                list1.Add(new boy(21, "刘伟"));
                list1.Add(new boy(26, "刘洋"));
                list1.Add(new boy(3, "刘英男"));
                list1.Add(new boy(19, "秦阳"));
                list1.Add(new boy(15, "宗康"));
                list1.Add(new boy(19, "保刚"));
                list1.Add(new boy(26, "王豪"));
                list1.Add(new boy(108, "威震天"));
                list1.Add(new boy(25, "毋振华"));
                list1.Add(new boy(20, "杨韬"));
                list1.Add(new boy(18, "赵帅"));


                list1 =list1.OrderBy(u => u.age).ToList(); 


                for (int i = 0; i < list1.Count; i++)
                {
                    
                    Console.WriteLine( list1[i].SelfIntroduction());




                 }
                


            }






        }
    }
}

你可能感兴趣的:(练习程序)