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.