Reputation: 5041
I have a dilemma that I need help with. The method TAXCheckControlNumberForAccuracy
goes into the database and does a Select *
statement using the passed in variables.
However, each time the program runs any one of these variables could be null. All could be null. None could be null. (i'm using OCR to get the variables..so it is not always accurate)
Can someone give me some insight on the best way to solve this problem.
if ((City != null) && (Zip != null) && (State != null) && (Owner != null))
{
if (City.Length > 4)
{
ControlNumberMatch = TAXCheckControlNumberForAccuracy(Owner, Zip, State, City);
}
}
Upvotes: 0
Views: 65
Reputation: 7789
Regardless of what you do, you still need to check each parameter individually. Create a method that does such.
void string CorrectParam(string param)
{
if (param == null)
return "default";
return param;
}
void TAXCheckControlNumberForAccuracy(string City, string Zip, string State, string Owner)
{
}
//call using this
TAXCheckControlNumberForAccuracy(CorrectParam(City), CorrectParam(Zip), CorrectParam(State), CorrectParam(Owner));
Upvotes: 1
Reputation: 32691
you can use a method with optional parameters. Like
public void TAXCheckControlNumberForAccuracy(string Owner = "default",
string Zip = "default",string State = "default",string City = "default");
Upvotes: 2