HomeCSharpC# Error CS0571 – ‘{0}’: cannot explicitly call operator or accessor

C# Error CS0571 – ‘{0}’: cannot explicitly call operator or accessor

C# Error

CS0571 – ‘{0}’: cannot explicitly call operator or accessor

Reason for the Error & Solution

‘function’ : cannot explicitly call operator or accessor

Certain operators have internal names. For example, op_Increment is the internal name of the ++ operator. You should not use or explicitly call such method names.

The following sample generates CS0571:

// CS0571.cs  
public class MyClass  
{  
   public static MyClass operator ++ (MyClass c)  
   {  
      return null;  
   }  
  
   public static int prop  
   {  
      get  
      {  
         return 1;  
      }  
      set  
      {  
      }  
   }  
  
   public static void Main()  
   {  
      op_Increment(null);   // CS0571  
      // use the increment operator as follows  
      // MyClass x = new MyClass();  
      // x++;  
  
      set_prop(1);      // CS0571  
      // try the following line instead  
      // prop = 1;  
   }  
}  

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...