Search code examples
c#visual-studio-2019assignment-operator

How to fix "The * or -> operator must be applied to a pointer"?


I'm studying about Assignment Operators in C# using Visual Studio 2019 but the script is not running due the error code CS0193.

First I changed the position of "+" add sign behind the "=" equivalent sign just like that { c =+ a } but it only work with add and sub. I want to use { c *= a} but getting following error.

            int a = 21;

            int c =+ a;

            Console.WriteLine("1. Value of c is {0}", c );

            Console.WriteLine("2. Binery of c is {0}", Convert.ToString(c, 2));

            Console.ReadLine();

well according to my book it should work like ( x -= y ), (x += y), (x *= y) … but in Visual studio 2019 is work like (x =- y), (x =+ y), error, error …

Error code: CS0193

Description: The * or -> operator must be applied to a pointer.


Solution

  • You're mixing declaration and assignment. You can only use *= (and += and -= and ++) on an already declared variable. So you need to do something like:

    int a = 21;
    
    int c = 1;
    
    c *= a;