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

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.