I have a vb.net function that expects 2 parameters - example :
GetCustomer(byval Addr1 as string, byval Addr2 as string).
The calling program calls this function by passing 2 string variables,example:
myCustomer = GetCustomer(strAddr1, strAddr2)
The function works well when both strAddr1 and strAddr2 have string values. However, sometimes strAddr2 is NULL. In that case, when the function is called, I get an error: Overload resolution failed because no Public 'GetCustomer' is most specific for these arguments..
One way I know how to fix this problem is to create an Overloaded copy of GetCustomer function with only strAddr1 as prameter. Likethis the index is different. In this case the calling program will first check if strAddr2 is null, and call appropriate version of GetCustomer.
However, I want to be able to use only single version of GetCustomer without creating overloaded copy because there is too much of code init to duplicate. Therefore is there a way to keep the GetCustomer function with 2 parameters, and calling program still able to pass a null vaue to one of its prameters ? Can I define type of parameters in Getcustomer function to something other than string, like say unknown type ?
These are just examples from a more complex requirement, but the parameters being passed may be nulls, string or integers and one function needs to handle them all without creating multiple overloaded copies.
Thanks.
Start Free Trial