C# Error CS0571 – ‘function’ : cannot explicitly call operator or accessor

C# Compiler Error

CS0571 – ‘function’ : cannot explicitly call operator or accessor

Reason for the Error

You will get this error in your C# code when you are trying to overload an operator and have used the internal name of that operator

For example, let’s compile the below C# program

using System;

namespace DeveloperPublishConsoleCore
{
    internal class Program
    {
        public static Program operator ++(Program c)
        {
            return null;
        }

        static void Main(string[] args)
        {
            op_Increment(null);
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

You will receive the error code CS0571 because you are using op_Increment which is an internal name of the ++ operator.

Error CS0571 ‘Program.operator ++(Program)’: cannot explicitly call operator or accessor DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 14 Active

C# Error CS0571 – 'function' : cannot explicitly call operator or accessor

Solution

In C#, certain operators have internal names. You should not use the internal names or explicitly call those method names. In the above example, you should avoid calling op_Increment.

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