0

Hi

I want to make an abstract method. But I always get the error " cannot declare a body because it is marked abstract."
When I delete the return then I get the error than I need a return.

can someone help me please

public  abstract Graphics drawRectangle(Graphics drawarea)
        {
          return drawarea;
        }
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
1

The very definition of an abstract method in C# is a function declaration without an implementation. Non-abstract derived classes are required to provide the implementation. If you want to provide a default implementation, the method should be virtual rather than abstract.

If you want to keep it abstract just replace the body with a semicolon. That makes it a declaration rather than a definition:

public abstract Graphics drawRectangle(Graphics drawarea);

Edited by Narue: n/a

1

Abstract method cannot have any code implementation.
Only overriden from it.

Edited by Mitja Bonca: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.