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

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