.net - C# Method parameter incorrectly updates -


i have following c# simple code :

public class error {     public string errordescription { get; set; }     public string errorcode { get; set; } }  public class request {     public error requesterror { get; set; } }  public class response {     public error responseerror { get; set; } }  public response process(request request)     {         var r = new response         {             responseerror = request.requesterror         };          r.responseerror.errordescription = "new response description";          return r;     } 

i call process through console app :

var request = new request {     requesterror = new error()     {         errorcode = "request error code",         errordescription = "request error description"     } };  var service = new service(); var response = service.process(request); debug.writeline("request errordescription = " + request.requesterror.errordescription); 

why request.responseerror.errordescription equal "new response description"; have not updated request object , it's not called out/ref. update response object return.

what doing wrong?

thanks

this start of problem:

responseerror = request.requesterror; 

you have single error object - after line, response , request both refer same object. bear in mind error class, values of request.requesterror , response.responseerror references.

you modify object here:

r.responseerror.errordescription = "new response description"; 

if still don't understand, might want read article on references , values.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -