I have a class with several string fields. This class represents a model for a serialization, so I have to check the length of its fields.
I do so with
public String Address {
get { return this.address; }
set {
if (value.Length > 15)
{
this.address= value.Substring(0,15);
}
else { this.address = value; }
}
}
All previous properties are being successfully set, but at certain point I get an error of 'null reference exception'.
I would avoid a solution like
public String Address {
get { return this.address; }
set {
if(value!=null){
if (value.Length > 15)
{
this.address= value.Substring(0,15);
}
else { this.address = value; }
}
}
}
What do you suggest?