Is there something in c# similar to java's @override annotation?

廉价感情. 提交于 2019-12-04 23:05:25

The C# compiler provides compile-time checking for method overrides, including checking if the method is actually overriding as you intended. You can indicate that a method should be overridden using the .NET override keyword.

SLaks

In C#, you must use the override keyword to override functions.

If you use override without a matching virtual or abstract base function, you'll get a compiler error.

If you don't use override, and there is a matching base function, you'll get a compiler warning (unless you add new).

In CSharp, override keyword meaning is totally different from the Java world. The equivalent in Csharp World is explicit implementation but it has a drawback.

interface IShape
{
     void Display();
}

class Square : IShape
{
     void IShape.Display()
     {

     }
}

No, yes. It makesn o sesne to have an anotation because in C# there is an override kkeyword in the langauge and the compiler warnds if you "hide" a method. So, either you say "new" or "override" directly as part of the method.

Java basically uses the annotation to hide a mistake in the langauge specifications.

Please read the language specificastions for C#. Completely.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!