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();
            }
        }
    }
  • 相关阅读:
    远程连接mysql root账号报错:2003-can't connect to MYSQL serve
    php定位并且获取天气信息
    PHP Ajax 跨域问题最佳解决方案
    AngularJS 过滤器
    AngularJS自定义指令及指令配置项
    php获取微信的openid
    SVN服务器
    redis的LRU策略理解
    golang入门案例之http client请求
    golang入门案例之SOCKET
  • 原文地址:https://www.cnblogs.com/sulong/p/4798546.html
Copyright © 2011-2022 走看看