C# Error CS0180 – ‘member’ cannot be both extern and abstract

C# Compiler Error

CS0180 – ‘member’ cannot be both extern and abstract.

Reason for the Error

You will receive this error when you have used both abstract and extern keywords on a member. Both of these keywords (abstract and extern) are mutually exclusive in C#.

For example, lets try to compile the below code snippet.

namespace DeveloperPubNamespace
{
    public class Class1
    {
        // This will return with CS0180 Error.
        public extern abstract int Method1(int a); 

    }
    class Program
    {
        static void Main(string[] args)
        {
        
        }
    }
  
}

The above code snippet will result with the error code CS0180 because the Method1 is marked as both extern and abstract.

Error CS0180 ‘Class1.Method1(int)’ cannot be both extern and abstract ConsoleApp3 C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 7 Active

Solution

To fix the error, remove either the extern keyword abstract and change your logic accordingly. Below is a code snippet showing how the error is fixed by removing the extern.

namespace DeveloperPubNamespace
{
    public class Class1
    {
        public extern int Method1(int a); 

    }
    class Program
    {
        static void Main(string[] args)
        {
        
        }
    }
  
}

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