I am trying to add a helper method to scrub out any non-alphanumeric characters in my class. However, I keep getting the error
NullReferenceException: Object reference not set to an instance of an object.
Not sure what I'm doing wrong here since I thought this was the proper way to set up any kind of validation within a class. Any suggestions would be appreciated.
private string agentId;
public string AgentId
{
get { return agentId; }
set { agentId = this.scrubAgentId(); }
}
private string scrubAgentId()
{
char[] arr = this.AgentId.ToCharArray();
arr = Array.FindAll<char>(arr, (c => (char.IsLetterOrDigit(c))));
return new string(arr);
}
char[] arr = this.AgentId.ToCharArray();