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()
{
}
}