Error : The Out Parameter must be assigned before control leaves the current method

后端 未结 2 1370
你的背包
你的背包 2020-12-06 04:09

While sending back parameters getting this error

Error : The Out Parameter must be assigned before control leaves the current method

相关标签:
2条回答
  • 2020-12-06 04:54

    You need to initialise those variables ;

    it must hold some value before returned from the Getpapers() method

    0 讨论(0)
  • 2020-12-06 04:57

    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.

    0 讨论(0)
提交回复
热议问题