Invalid token '=' in class, struct, or interface member declaration { get; } =

If you are getting errors like:

Invalid token ‘=’ in class, struct, or interface member declaration

when you compile your code in Visual Studio and the class looks something like:

public class Point(int x, int y) 
{ 
    public int X { get; } = x; 
    public int Y { get; } = y; 
}

then you will need to install the new Roslyn compiler from Microsoft. The error you are getting is because the new compiler has many new language features that are not compatible with the previous compiler. The above code is an example of the new Primary Constructors feature

comments powered by Disqus