I want to assign some default value to a property or want to replace some character like given below. Is it a correct syntax or should i do this by creating a variable.
public string Login_Name
{
get
{ return this.Login_Name; }
set { this.Login_Name = value.Replace("'", "''"); }
}
By accessing
Login_Namethegetwill returnLogin_Nameagain leaving you with an infinite loop (StackOverflowException).You should use properties to get and set private members:
If you meant to use an auto-implemented property, it would look like this:
But auto-implemented properties cannot have any additional logic applied to their gets or sets.