简体   繁体   English

C# 隐藏接口成员

[英]C# hidding interface members

Consider the following code:考虑以下代码:

interface IA
{
   string text {get;}
}
interface IB: IA
{
   int number {get;}
}
class MyType: IB
{
   {...}
}

I realy don't want to implement property "text" from IA in MyType.. Is there any possible trick?我真的不想在 MyType 中实现来自 IA 的属性“文本”。有什么可能的技巧吗? For example, IB hides property..例如,IB 隐藏属性..

Thanks谢谢

Yeah, you can make it pseudo-private by implementing it explicitly like this:是的,您可以通过像这样显式实现它来使其成为伪私有:

class MyType: IB
{
    string IA.text { get { throw new NotSupportedException(); } }
}

But like, really?但是,真的吗? Violating your own contract is, like, well, ... a Violation, man!违反你自己的合同,就像,嗯,……违反,伙计!

Have fun using it I guess?我猜使用它玩得开心吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM