c#.net中的接口 [英] Interface in c# .net

查看:78
本文介绍了c#.net中的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给我一个合适的例子来帮助我理解这个艺术品。



我的想法是这样的。



1.我们是否明确声明了接口方法Virtual。示例



2.如果接口方法被密封,派生类不能覆盖该方法。但是,派生类可以重新继承相同的接口并且可以提供它自己的接口方法实现。它是什么意思。











CLR要求将接口方法标记为虚拟。如果未在源代码中将该方法明确标记为虚拟,则编译器将该方法标记为虚拟并密封;防止派生类重写接口方法。 如果将方法明确标记为虚拟 ,则编译器将该方法标记为虚拟(并使其保持未密封状态);这允许派生类重写接口方法。 如果接口方法被密封,派生类不能覆盖该方法。但是,派生类可以重新继承相同的接口,并可以为接口提供自己的实现。方法。





请求帮助我清楚地理解上面的段落,我将非常感谢你。

please help me understanding the artical by giving me an suitable Example.

my dought is that .

1.Does we declare the interface method Virtual explicitly . example

2." If an interface method is sealed, a derived class cannot override the method. However, a derived class can re-inherit the same interface and can provide its own implementation for the interface’s methods. " what does it mean.





"The CLR requires that interface methods be marked as virtual. If you do not explicitly mark the method as virtual in your source code, the compiler marks the method as virtual and sealed; this prevents a derived class from overriding the interface method. If you explicitly mark the method as virtual, the compiler marks the method as virtual (and leaves it unsealed); this allows a derived class to override the interface method. If an interface method is sealed, a derived class cannot override the method. However, a derived class can re-inherit the same interface and can provide its own implementation for the interface’s methods."


pleas help me to make the clear understanding of the above paragraph i will be very thankful to you.

推荐答案

尝试:

接口在C-For-Beginners [ ^ ]

interface-best-example-in-csharp [ ^ ]

csharp_interfaces [ ^ ]

如何实现 - 界面 - 明确地用虚拟方法 [ ^ ]

explicit-interface-implementation-cannot-be-virtua [ ^ ]

why-implement-interface-explicit [ ^ ]
try with:
Interfaces-in-C-For-Beginners[^]
interface-best-example-in-csharp[^]
csharp_interfaces[^]
how-to-implement-an-interface-explicitly-with-a-virtual-method[^]
explicit-interface-implementation-cannot-be-virtua[^]
why-implement-interface-explicitly[^]


您好朋友,请访问以下文章了解C#中的界面:

C#中的接口(对于初学者) [ ^ ]

希望这会对你有所帮助。 :)

- DD
Hello friend, please visit the following article to understand Interface in C#:
Interfaces in C# (For Beginners)[^]
Hope this will help you. :)
- DD


这篇关于c#.net中的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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