Search code examples
c#.netpropertiesframeworkswindows

Error 1 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement


public partial class frmManager : Form
{
    public String Name
    {
        get 
        {
            txtName.Text;
        }
        set;
    }
}

Error 1 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement


Solution

  • If you want to use the getter and setter and define a custom getter you also need to define a custom setter. For eg :

        public String Name
        {
            get { return txtName.Text; }
            set { txtName.Text = value; }
        }
    

    Or you can create "get only" (so readonly) properties :

        public String Name
        {
            get { return txtName.Text; }
        }