Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've used the @Override in java and has come in quite handy. Is there anything similar in c#?

like image 971
xecaps12 Avatar asked May 17 '11 02:05

xecaps12


2 Answers

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.

like image 79
mellamokb Avatar answered Oct 14 '22 05:10

mellamokb


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).

like image 45
SLaks Avatar answered Oct 14 '22 06:10

SLaks