I\'ve used the @Override in java and has come in quite handy. Is there anything similar in c#?
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.
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.
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()
{
}
}