• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
༺҉戰҉༻
博客园    首页    新随笔    联系   管理    订阅  订阅

面向对象 理解 C#复习

面向对象:

      是基于万物皆对象这个哲学观点. 所谓的面向对象就是将我们的程序模块化,对象化,把具体事物的特性属性和通过这些属性来实现一些动作的具体方法放到一个类里面

通俗点讲:

一切都是对象

举例:

将一栋房子 比作一个对象 【房子:对象】。 从图上也可以看到这是一种新类别的房子【房子:类-Class】  如图

这就是对象,那对象应该包含什么呢?

面向对象的三项基本特征:封装、继承、多态。

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

namespace _11._24
{
    class Program
    {
        struct student
        {
            public string code;
            public string name;
            public double score;
        }
        static void Main(string[] args)
        {
            ArrayList al = new ArrayList();
            Console.Write("请输入学生人数:");
            int a = int.Parse(Console.ReadLine());
            for (int i = 0; i < a; i++)
            {
                student st = new student();
                for (; ; )
                {
                    Console.Write("请输入第{0}个学生的学号:", i + 1);
                    string b = Console.ReadLine();
                    if (b.StartsWith("S"))
                    {
                        st.code = b;
                        break;
                    }
                }
                for (; ; )
                {
                    Console.Write("请输入第{0}个学生的姓名:", i + 1);
                    string c = Console.ReadLine();
                    if (c != "")
                    {
                        st.name = c;
                        break;
                    }
                }
                for (; ; )
                {
                    Console.Write("请输入第{0}个学生的成绩:", i + 1);
                    try
                    {
                        double d = double.Parse(Console.ReadLine());
                        if (d <= 100 && d >= 0)
                        {
                            st.score = d;
                            break;
                        }
                    }
                    catch
                    { Console.WriteLine("请输入数字!"); }
                }
                al.Add(st);
            }
            for (int i = 0; i < al.Count - 1; i++)
            {
                for (int j = i + 1; j < al.Count; j++)
                {
                    student s1 = (student)al[i];
                    student s2 = (student)al[j];
                    if (s1.score < s2.score)
                    {
                        Object b = al[i];
                        al[i] = al[j];
                        al[j] = b;
                    }
                }
            }
            Console.Write("序号" + "\t" + "学号" + "\t" + "姓名" + "\t" + "成绩" + "\n");
            for (int i = 0; i < a; i++)
            {
                student s = (student)al[i];
                Console.Write((i + 1) + "\t" + s.code + "\t" + s.name + "\t" + s.score + "\n");
            }
            Console.ReadLine();
        }
    }
}
View Code

 

posted @ 2016-11-24 15:22  孤丷狼  阅读(212)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3