面向对象:
是基于万物皆对象这个哲学观点. 所谓的面向对象就是将我们的程序模块化,对象化,把具体事物的特性属性和通过这些属性来实现一些动作的具体方法放到一个类里面
通俗点讲:
一切都是对象
举例:
将一栋房子 比作一个对象 【房子:对象】。 从图上也可以看到这是一种新类别的房子【房子:类-Class】 如图
这就是对象,那对象应该包含什么呢?
面向对象的三项基本特征:封装、继承、多态。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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(); } } }