当前位置: 首页 > news >正文

显式接口实现(C# 编程指南)

接口的实现可以有多种方式,下面是C#接口实现的几种方式欢迎交流

两个接口包含签名相同的成员

如果一个类实现的两个接口包含签名相同的成员,则在该类上实现此成员会导致这两个接口将此成员用作其实现。 如下示例中,所有对 Paint 的调用皆调用同一方法。 第一个示例定义类型:
public interface IControl
{
void Paint();
}
public interface ISurface
{
void Paint();
}
public class SampleClass : IControl, ISurface
{
// Both ISurface.Paint and IControl.Paint call this method.
public void Paint()
{
Console.WriteLine(“Paint method in SampleClass”);
}
}
下面的示例调用方法:

SampleClass sample = new SampleClass();
IControl control = sample;
ISurface surface = sample;

// The following lines all call the same method.
sample.Paint();
control.Paint();
surface.Paint();

// Output:
// Paint method in SampleClass
// Paint method in SampleClass
// Paint method in SampleC

http://www.lryc.cn/news/105016.html

相关文章:

  • element-ui 图片上传 及 quillEditor富文本(图片视频上传)
  • 前端技术Vue学习笔记--002
  • 【RabbitMQ(day4)】SpringBoot整合RabbitMQ与MQ应用场景说明
  • 想了解好用的翻译pdf的软件吗?
  • docker安装nginx并配置SSL
  • 【LeetCode 算法】Reorder List 重排链表
  • MQ面试题3
  • 【Linux命令200例】patch 用于将补丁文件应用到源码中
  • 一起来学算法(邻接矩阵)
  • hadoop与HDFS交互
  • MYSQL 分区如何指定不同存储路径(多块磁盘)
  • 安全加固服务器
  • Linux 命令学习:
  • 牛客网Verilog刷题——VL54
  • 学习系统编程No.34【线程同步之信号量】
  • SolidUI社区-Snakemq 通信源码分析
  • 【大数据之Flume】四、Flume进阶之复制和多路复用、负载均衡和故障转移、聚合案例
  • 前端学习--vue2--插槽
  • 使用 Docker Compose 部署 Redis Cluster 集群,轻松搭建高可用分布式缓存
  • 在Spring Boot框架中集成 Spring Security
  • 登月再进一步:Apollo自动驾驶的里程碑
  • 嵌入式一开始该怎么学?学习单片机
  • Spring事件监听器ApplicationListener
  • 安全学习DAY10_HTTP数据包
  • 云原生落地实践的25个步骤
  • Stable diffusion 三大基础脚本 提示词矩阵,载入提示词,XYZ图表讲解
  • uniapp uni-combox 下拉提示无匹配项(完美解决--附加源码解决方案及思路)
  • 10. Mybatis 项目的创建
  • 历年 Nobel prize in Physics (诺贝尔物理学奖)简介
  • IDEA中Git面板操作介绍 变基、合并、提取、拉取、签出