zoukankan      html  css  js  c++  java
  • 面向对象 理解 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("序号" + "	" + "学号" + "	" + "姓名" + "	" + "成绩" + "
    ");
                for (int i = 0; i < a; i++)
                {
                    student s = (student)al[i];
                    Console.Write((i + 1) + "	" + s.code + "	" + s.name + "	" + s.score + "
    ");
                }
                Console.ReadLine();
            }
        }
    }
    View Code
  • 相关阅读:
    会话技术——Cookie
    Servlet——Request和Response
    #Servlet——Web之间跳转和信息共享、三大作用域对象
    8个技巧教你区分LED灯具优劣
    建筑景观LED照明设计要考虑哪些?
    荧光材料物理特性对白光LED光输出冷热比的影响
    金刚战神D系列户外全彩D5.92
    2020爱你爱你,海佳集团祝您新年快乐!
    复制文本
    超市会员系统
  • 原文地址:https://www.cnblogs.com/shadow-wolf/p/6097964.html
Copyright © 2011-2022 走看看