zoukankan      html  css  js  c++  java
  • C#----接口的显式实现

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 接口
    {
        public interface IWindlows
        {
            void Close();
        }
        public interface IFile
        {
            void Close();
        }
        public class Windows:IWindlows,IFile //这两个接口有包含共同的方法  但是实现确实相同 而且不能同时这样实现2次   这种情况下需要显示实现
        {
            //public void Close()
            //{
            //    Console.WriteLine("关闭窗口");
            //}
    
            void IWindlows.Close()
            {
                Console.WriteLine("关闭窗口");
            }
            void IFile.Close()
            {
                Console.WriteLine("关闭文件");
            }
        }
       public class TnterfaceTest2 
        {
           public static void Test1()
           {
               Windows k = new Windows();                              //k不能使用Close方法 显式实现接口 默认是Private的
               IFile test = new Windows();                                  //把其当接口则可以使用这些方法
               test.Close();
               IWindlows test1 = new Windows();
               test1.Close();
               
               
           }
        }
    }
  • 相关阅读:
    mkdir,rmdir
    linux目录结构
    echo
    date
    man
    cd
    ls
    线程、进程
    php类型的自动转换
    电商
  • 原文地址:https://www.cnblogs.com/keiling/p/3651339.html
Copyright © 2011-2022 走看看