C# Error CS0501 – ‘member function’ must declare a body because it is not marked abstract, extern, or partial

C# Compiler Error

CS0501 – ‘member function’ must declare a body because it is not marked abstract, extern, or partial

Reason for the Error

You’ll get this error in your C# code when you try to declare a function without a body.

For example, let’s try to compile the below C# code snippet.

C#

You’ll receive the error code CS0501 because the C# compiler has detected that you have declared a non-abstract method SetId() without the method body.

Error CS0501 ‘Employee.SetId()’ must declare a body because it is not marked abstract, extern, or partial DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 6 Active

C# Error CS0501 – 'member function' must declare a body because it is not marked abstract, extern, or partial

Solution

Non-abstract methods in C# must have a method body or implementation. You can fix this error in your C# program by adding the implementation or method body when declaring the function.

C#

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...