While sending back parameters getting this error
Error : The Out Parameter must be assigned before control leaves the current method
You need to initialise those variables ;
it must hold some value before returned from the Getpapers() method
You are assigning Id1
and Id2
inside an if statement and compiler can't determine if it will be assigned a value at run time, thus the error.
You could assign them some default value before the if statement. Something like.
Id1 = 0;
Id2 = 0;
if (rdr.Read())
{
Id1 = (int)rdr["ID1"];
Id2 = (int)rdr["ID2"];
}
or specify some default values in else
part of your condition.
An out
type parameter must be assigned some value, before the control leaves the functions. In your case, compiler can't determine whether your variables will be assigned or not, because it is being assigned inside an if
statement.
See: 5.3 Definite assignment
At a given location in the executable code of a function member, a variable is said to be definitely assigned if the compiler can prove, by static flow analysis, that the variable has been automatically initialized or has been the target of at least one assignment.