C#接口 - 只有在实现其他接口的接口 [英] C# Interfaces- only implement an interface in other interfaces

查看:133
本文介绍了C#接口 - 只有在实现其他接口的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想唯一的接口中实现某些接口,我不希望他们能够被一个类继承直接

I would like to only implement certain interfaces within other interfaces, I don't want them to be able to be inherited directly by a class.

在此先感谢!

推荐答案

您不能在C#中做到这一点 - 任何类可以实现它可以访问任何接口。

You can't do this in C# - any class can implement any interface it has access to.

为什么要这么做?请记住,通过声明的接口继承:

Why would you want to do this? Bear in mind that by declaring an interface inheritance:

public interface InterfaceA {}
public interface InterfaceB : InterfaceA {}

您所指定的任何实施 InterfaceB 也有实施了InterfaceA ,所以你会得到实现的类了InterfaceA 反正。

You're specifying that anything implementing InterfaceB also has to implement InterfaceA, so you'll get classes implementing InterfaceA anyway.

这篇关于C#接口 - 只有在实现其他接口的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆