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.