C# Error CS0023 – Operator ‘operator’ cannot be applied to operand of type ‘type’

C# Compiler Error Message

CS0023 – Operator ‘operator’ cannot be applied to operand of type ‘type’

Reason for the Error

You will usually receive this error when you attempt to apply an operator to a variable whose type is not designed with that.

For example, the below code snippet will result with the error CS0023 as ++ is not allowed on strings.

public class DeveloperPublish
{
    public static void Main()
    {
        string input = "Welcome to Senthil Kumar's blog";
        input = input++; 
    }
}

Error CS0023 Operator ‘++’ cannot be applied to operand of type ‘string’ ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 6 Active

C# Error CS0023 - Operator 'operator' cannot be applied to operand of type 'type'

Solution

To fix this error, remove the unsupported operator that is been used with a operator in C#.

Copy link
Powered by Social Snap