Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim property in get method

Tags:

c#

At the moment I'm doing something like:

public virtual String zipcodeRaw { get; set; }
public virtual String zipcode {
    get
    {
        return zipcodeRaw.Trim();
    }
}

Is there a way I can do something like:

public virtual String zipcode {
    get
    {
        return zipcode.Trim();
    }
}
like image 768
iKode Avatar asked Dec 16 '22 03:12

iKode


1 Answers

That would give you an infinite loop since zipcode refers to itself. However, properties are just public accessors and modifiers for a private variable. You could certainly do:

private string _zipcode;

public virtual string zipcode {
   get { return _zipcode.Trim(); }
}
like image 62
OnResolve Avatar answered Dec 18 '22 18:12

OnResolve