C# Error CS0564 – The first operand of an overloaded shift operator must have the same type as the containing type

C# Error

CS0564 – The first operand of an overloaded shift operator must have the same type as the containing type

Reason for the Error & Solution

The first operand of an overloaded shift operator must have the same type as the containing type, and the type of the second operand must be int

You attempted to overload a shift operator (<< or >>) with incorrectly typed operands. The first operand must be the type and the second operand must be of the type int.

The following sample generates CS0564:

// CS0564.cs  
using System;  
class C  
{  
   public static int operator << (C c1, C c2) // CS0564  
// To correct, change second operand to int, like so:  
// public static int operator << (C c1, int c2)  
   {  
      return 0;  
   }  
   static void Main()
   {  
   }  
}  

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