码迷,mamicode.com
首页 > 其他好文 > 详细

stuct+ArrayList的for用法

时间:2015-04-19 17:52:30      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

namespace ConsoleApplication1
{
    class Program
    {
        struct xs
        {
           public string name;
            public double shuxue;
            public double yuwen;
            public double waiyu;
            public double zongfen;
        }
        static void Main(string[] args)
        {
            ArrayList al = new ArrayList();
            Console.Write("请输入学生的个数:");
            int n = Convert.ToInt32(Console .ReadLine ());
                for (int i = 1; i <= n; i++)
            {
                xs t = new xs();
                Console.Write("输入第"+i+"个同学的姓名:");
                t.name = Console.ReadLine();
                Console.Write("请输入数学分数:");
                t.shuxue = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入语文分数:");
                t.yuwen = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入外语分数:");
                t.waiyu= Convert.ToInt32(Console.ReadLine());
                t.zongfen = t.shuxue + t.yuwen + t.waiyu;
                al.Add(t);
            }
            for (int i = 1; i <= al.Count-1; i++)
            {
                for (int j = 1 ; j <= al.Count-i; j++)
                {
                   
                    if (((xs)al[j]).zongfen >((xs)al[j-1]).zongfen )
                    {
                        xs tepm = (xs)al[j];
                        al[j] = al[j - 1];
                        al[j - 1] = tepm;
                    }
                }
            }
            for (int i = 0; i <al.Count ; i++)
            {
                Console.WriteLine("姓名" + ((xs)al[i]).name + "\t数学" + ((xs)al[i]).shuxue + "\t语文" + ((xs)al[i]).yuwen + "\t外语" + ((xs)al[i]).waiyu + "\t总分" + ((xs)al[i]).zongfen + "\t名次" + (i+1));
            }
            Console.ReadLine();
        }
    }
}

 

stuct+ArrayList的for用法

标签:

原文地址:http://www.cnblogs.com/dlexia/p/4439395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!