Two errors in a simple code, Invalid token ‘=’ , a ‘field’ but is used like a ‘type’ [closed]

You can only use assignment in a class definition if it is part of member initialization, as in int a = 1;, or in a method/constructor/property body, so if you want to assign a value right after initializing it, you’d have to put it in the constructor:

public Form1()
{
    a = 2;
    InitializeComponent();
}

Leave a Comment