Hi guys i’m having a problem regarding returning multiple values from a method. I’m using ‘out’ to return other value from a method, here the snippet:
public DataTable ValidateUser(string username, string password, out int result)
{
try
{
//Calls the Data Layer (Base Class)
if (objDL != null)
{
int intRet = 0;
sqlDT = objDL.ValidateUser(username, password, out intRet);
}
}
catch (Exception ex)
{
ErrorHandler.Handle(ex);
OnRaiseErrorOccuredEvent(this, new ErrorEventArgs(ex));
}
return sqlDT;
}
then when i compile having a error like this:
“The out parameter ‘return’ must be assigned to before control leaves the current method”
Anyone guys can help me solve this.
That means in all possibilities (inside and outside the if, in the catch), your result variable must be assigned.
The best approach would be to give it a default value at the start of the function: