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

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