zoukankan      html  css  js  c++  java
  • C#接口

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    /*
     * 1、接口表示一组函数成员而不实现成员的引用类型
     * 2、只有类和结构可以实现接口,必须实现接口中的全部成员
     * 3、接口可以继承接口
     * 4、将类强制转换为类引用为实现的接口的引用时,会抛出异常;用 as 运算符来避免,转换不成功则值为null
     *      ILiveBirth lb =a as ILiveBirth
     *      if(lb!=null)
     * 5、类可以实现任意数量的接口,这些接口成员有重复时,类可以实现单个成员来满足所有包含重复成员的接口。
     * 也可以创建显式接口实现,在实现成员时,限定接口名
     * 
     * 
     */
    namespace ExInterFace
    {
        interface IIfc
        {
            void PrintOut(string s);
        }
        class MyClass : IIfc 
        {
            public void PrintOut(string s)
            {
                Console.WriteLine("Calling through {0}",s);
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                MyClass mc = new MyClass();
                mc.PrintOut("Object");
                IIfc ifc1 = (IIfc)mc;
                ifc1.PrintOut("Interface");
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    redis 资料
    php 安装redis php扩展
    Unity生命周期
    疫情下的大学生人格发展研究
    对联一句——百花深处
    Unity实现byte[]合成图像
    Unity实现精灵资源动态加载
    数据结构与算法初步
    Unity中激活子物体
    C#实现自定义列表
  • 原文地址:https://www.cnblogs.com/sulong/p/4798546.html
Copyright © 2011-2022 走看看