Compiler Error CS0501

'member function' must declare a body because it is not marked abstract, extern, or partial

Nonabstract methods must have implementations.

Explanation

In C#, methods/functions that are a part of a class must have a "body", or implementation. The compiler needs to know what should happen when these methods are called, so that it knows what to execute. A method with no body is not acceptable to the compiler because it wants to avoid confusion about the intent of the code.

There are exceptions to this rule:

Example

The following sample generates CS0501:

public class MyClass
{  
   public void MethodWithNoBody();   // CS0501 declared but not defined  
}  

This could be fixed by declaring a body (by adding brackets):

public class MyClass
{  
   public void MethodWithNoBody() { };   // No error; compiler now interprets as an empty method
}  

Or, using an appropriate keyword, such as defining an abstract method:

abstract class MyClass // class is abstract; classes that inherit from it will have to deifne MyAbstractMethod
{  
   public abstract void MyAbstractMethod();   // Compiler now knows that this method must be deinfed by inheriting classes.
}