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

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