c# - How to assign out parameter in function? -
i have method returns object , has out parameter. method calls method takes in same out paramter out paramter. gives build error on return statement:
the out parameter 'param1' must assigned before control leaves current method
the code looks like:
public typea method1(typea param1, out bool param2) { /... logic here .../ submethod(out param2); /... logic here .../ return param1; } param2 manipulated in submethod(), not in method1(). there else need do?
in case, assign 'default' value. regardless of bool, int, myfoo, etc. - set default value.
public typea method1(typeb param1, out bool param2) { param2 = false; // default value; // or param2 = default(bool); // in cases not sure default /... logic here .../ submethod(out param2); /... logic here .../ return param1; // update: <- receiving exception } but need identify why exception refers 'param1' when param1 not @ fault in example ( for clarification : assuming typeb : typea , constrained).
i believe passing param2 out parameter in submethod(...) removes obligation assign param2. however, have not assigned param1. there more going on here has not been explained?
Comments
Post a Comment