c# - how solve below issue with out key word? -
here putting example facing problem code.. here have use reference types in code.
namespace outissue { class program { static int method(out int i, out int j, out int k) { = 44; j = 55; k = 67; int d = + j + k; return d; } static void main(string[] args) { int total, ,b,c; = 100; b = 200; c = 300; total = method(out a,out b, out c); console.writeline(total); } } }
here method have print result of 600 total. problem out keyword initialization. in application ref not recommended , should go out keyword only..
is there alternative way other out keyword have behave "ref or out"
note: not supposed use ref keyword can please me out this?
if homework assignment, think have misunderstood.
what have written, regardless of out keyword or ref keyword, return total of 166, because change values of local variables in method called method().
if asking understand ref keyword , out keywords do, recommend read http://www.dotnetperls.com/parameter , write example shows difference between when use ref, when use out , when use neither.
Comments
Post a Comment