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

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