HomeCSharpC# Error CS0193 – The * or -> operator must be applied to a pointer

C# Error CS0193 – The * or -> operator must be applied to a pointer

C# Compiler Error

CS0193 – The * or -> operator must be applied to a pointer

Reason for the Error

You will receive this error when you have used the * or -> operator with a non-pointer type in C#.

For example, try to compile the below code snippet.

namespace DeveloperPubNamespace
{
   class Employee
    {
        public int Id { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Employee emp = new Employee();
            emp->Id = 1;
        }
    }

}

In the above code snippet, we have a Employee class with a property Id. In the Main function, we have tried to create an instance of Employee and tried accessing the Id property of the instance using -> operator instead or the . operator. This results in the error code CS0193.

Error CS0193 The * or -> operator must be applied to a pointer ConsoleApp3 C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 12 Active

C# Error CS0193 - The * or -> operator must be applied to a pointer

Solution

To fix the error code CS0193, you will need to use the * or -> operator only on pointers and avoid using them on non-pointer types.

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