• 接口 Interface


    1.interface 关键字 声明接口;

    2.接口中的成员默认都是public 也不能加“访问修饰符”,只要一个类继承了这个接口,就必须实现这个接口中的所有成员;

    3.接口中只能有方法,属性,索引器,事件,不能有“字段”和 构造函数;

    4.接口和接口之间可以继承,并且可以多继承;接口不能继承类,类可以继承接口

    5.当虚方法继承接口时,需子类去实现;

    6.能力不一样的时候适合用接口;

    using System;
    using System.Collections;
    using System.Collections.Generic;
    namespace Dome
    {
        class dom
        {
            static void Main(string[] args)
            {
                play iplay = new student();
                iplay.iplay();
                Console.WriteLine();
                Console.ReadKey();
            }
        }
        public class person {//父类
            public void sayhello() { Console.WriteLine("我是人类"); }
        }
        public class student:person,play {//继承父类person和接口play  必须实现接口中的成员
            public void hello() { Console.WriteLine("我是学生"); }
            public void iplay() { Console.WriteLine("实现接口"); }
        }
        interface play {//接口中的成员默认是public
            void iplay();
        }
    }
     
    View Code

     显示实现接口

    using System;
    using System.Collections;
    using System.Collections.Generic;
    namespace Dome
    {
        class dom
        {
            static void Main(string[] args)
            {
                play iplay = new person();
                iplay.iplay();
                person p = new person();
                p.iplay();
                Console.ReadKey();
            }
        }
        public class person:play {
    
            void play.iplay()//显示实现接口
            {
                Console.WriteLine("我是接口中的方法");
            }
            public void iplay() //类中的方法
            { Console.WriteLine("我是类中的方法"); }
        }
       
        interface play {//接口中的成员默认是public
            void iplay();
        }
    }
     
    View Code
    时间就像海绵里的水,只要你愿意挤,总还是有的——鲁迅
  • 相关阅读:
    Linux命令学习—— fdisk -l 查看硬盘及分区信息
    UE4 Runtime下动态给Actor添加组件
    如何批量下载网站网页
    ue4 motage
    帧同步相关
    张瀚荣:如何用UE4制作3D动作游戏
    游戏服务器架构演进(完整版)
    Digital Mike头发制作及渲染的深度揭秘
    [UE4]如何替换角色Mesh上的Material材质
    [UE4]用C++如何创建Box Collision
  • 原文地址:https://www.cnblogs.com/syzly/p/6659904.html
Copyright © 2020-2023  润新知