c# – 实现具有“同名”属性的2个接口
发布时间:2020-12-15 06:35:32 所属栏目:百科 来源:网络整理
导读:这似乎是一个合理的(也许简单的)场景,但是你将如何做到以下几点: 说我有2个接口: Interface ISimpleInterface string ErrorMsg { get; } End InterfaceInterface IExtendedInterface string ErrorMsg { get; set; } string SomeOtherProperty { get; set;
这似乎是一个合理的(也许简单的)场景,但是你将如何做到以下几点:
说我有2个接口: Interface ISimpleInterface string ErrorMsg { get; } End Interface Interface IExtendedInterface string ErrorMsg { get; set; } string SomeOtherProperty { get; set; } End Interface 我想要一个类来实现两个接口: Public Class Foo Implements ISimpleInterface,IExtendedInterface 给定每个接口具有不同的访问级别,如何在类中定义ErrorMsg属性? 这里是我的场景,如果你想知道:我正在使用一个psuedo MVC arhitecture编写一个UserControl,其中UserControl将扩展接口暴露给它的Controller,并将Simple接口暴露给控件的消费者. 顺便说一下,在VB.NET中实现这一点(任何建议的vb中的synatx都不会感谢). 解决方法
您可以使用“显式接口”实现来实现其中一个或两个接口,因此编译器知道哪个ErrorMsg属性属于哪个接口.
要做到这一点,请简单地写:ISimpleInterface(对于C#)在你的类名后面,然后单击ISimpleInterface并选择实现显式接口. 更多信息:http://msdn.microsoft.com/en-us/library/aa288461(VS.71).aspx (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |