摘要: 静态类方法:不需要实例化,直接 类名.方法名,调用静态成员。 using System; using System.Collections.Generic; using System.Text; namespace 静态类和非静态类的区别 { public class Person { public 阅读全文
posted @ 2023-03-21 20:47 春哥博客 阅读(46) 评论(0) 推荐(0)
摘要: 用接口,可以让学生继承2个类, 接口是一种规范,一种能力,一种扩展 using System; namespace 多态之接口类 { class Program { static void Main(string[] args) { //接口就是一个规范、能力。 Student ss = new S 阅读全文
posted @ 2023-03-21 16:04 春哥博客 阅读(19) 评论(0) 推荐(0)
摘要: 当父类中的方法不知道如何去实现的时候,可以考虑将父类写成抽象类,将方法写成抽象方法 比如:狗狗会叫,猫咪也会叫,可以使用 abstract关键字标记一个抽象的动物类,抽象的方法 阅读全文
posted @ 2023-03-21 16:03 春哥博客 阅读(15) 评论(0) 推荐(0)
摘要: 多态:让一个对象能够表现出多种的状态(类型) 实现多态的3种手段:1、虚方法 2、抽象类 3、接口 1、虚方法 步骤: 1)将父类的方法标记为虚方法,使用关键字 virtual 2) 将子类的方法前面加个override,即可实现多态 阅读全文
posted @ 2023-03-21 16:03 春哥博客 阅读(25) 评论(0) 推荐(0)
摘要: using System; using System.Collections.Generic; namespace List_泛型集合 { class Program { static void Main(string[] args) { //创建泛型集合对象 List<int> list = ne 阅读全文
posted @ 2023-03-21 16:02 春哥博客 阅读(28) 评论(0) 推荐(0)
摘要: using System; using System.Collections; namespace Hashtable_键值对集合 { class Program { static void Main(string[] args) { //创建一个键值对集合对象 Hashtable ht = new 阅读全文
posted @ 2023-03-21 16:01 春哥博客 阅读(24) 评论(0) 推荐(0)
摘要: 1、ArrayList集合对象 using System; using System.Collections; namespace ArrayList集合 { class Program { static void Main(string[] args) { //创建了一个集合对象 ArrayLis 阅读全文
posted @ 2023-03-21 16:01 春哥博客 阅读(27) 评论(0) 推荐(0)
摘要: 1、里氏转换 1)子类可以赋值给父类 2)如果父类中装的是子类对象,那么可以将这个父类强转为子类对象 using System; namespace 里氏转换 { class Program { static void Main(string[] args) { //1、子类可以赋值给父类: //如 阅读全文
posted @ 2023-03-21 16:00 春哥博客 阅读(15) 评论(0) 推荐(0)
摘要: 继承:把这几个子类重复的成员单独拿出来封装成一个类,作为它们几个共同的父类 using System; namespace 继承 { class Program { static void Main(string[] args) { Student stu = new Student(); } pu 阅读全文
posted @ 2023-03-21 15:59 春哥博客 阅读(24) 评论(0) 推荐(0)
摘要: 作用:帮助我们初始化对象(给对象的每个属性依次赋值) 先创建对象 - 然后执行构造函数 构造函数是一个特殊的方法: 1)构造函数没有返回值,连void也不能写 2)构造函数的名称必须和类名一样(你的类叫Person,你的构造函数名字也得叫Person) 构造函数是可以有重载的 *** 类当中会有一个 阅读全文
posted @ 2023-03-21 15:58 春哥博客 阅读(31) 评论(0) 推荐(0)
摘要: 属性:保护字段的 属性的本质:两个方法,一个get方法(取值),一个set方法(赋值) using System; using System.Collections.Generic; using System.Text; namespace 属性 { public class Person { pr 阅读全文
posted @ 2023-03-21 15:57 春哥博客 阅读(30) 评论(0) 推荐(0)