c# - Variable declaration, does it create a reference to the actual object or a copy? -
i'm looking @ source of web application , can see loads of use cases sample code below. can't find info online when declaring local variable in c# (of complex type) , want sure if creates reference or copy of object. coming javascript background i'd imagine creates reference unless it's primitive data type.
the code this
customitemtype myvara = (customitemtype) this.session["var_1"]; // work on properties of var_1 int num2 = checked (myvara.items.count - 1); int index = 0; while (index <= num2) { myvara.items[index].statuscode = "posted"; checked { ++index; } } // save session this.session["var_1"] = (object) myvara; am right in thinking following line isn't needed.
// save session this.session["var_1"] = (object) myvara; as local variable myvara reference property in session if update local var you'll updating session object?
secondly, pose problem when each web page served in new thread these multiple threads accessing same session object , doing manipulations @ same time?
- primitive data types , structures (declared
struct) 'by value', clasess (declaredclass) 'by reference'. depends oncustomitemtypeis. - yes, pose potential threads synchronization issue. in simple case can put object manipulations inside
lockblock.
Comments
Post a Comment