c# - Get value from dictionary as reference -



c# - Get value from dictionary as reference -

i'm quite stuck c# dictionaries. i'm trying write cache using dictionary, can't seem work:

class programme { static dictionary<int, value> dict; static void main(string[] args) { dict = new dictionary<int,value>(); value v = new value() { hello = 1, bye = "qwerty"}; dict.add(1, v); value c = dict[1]; console.writeline(c.bye); dict[1] = new value() { hello = 2, bye = "asdf" }; console.writeline(c.bye); } } class value { public int hello {get;set;} public string bye {get;set;} }

current output:

qwerty qwerty

output i'm looking for:

qwerty asdf

edit:

i managed working now, using:

//dict[1] = new value() { hello = 2, bye = "asdf" }; dict[1].hello = 2; dict[1].bye = "asdf";

however, there way me update whole value rather manually updating each property?

it working correctly, problem using reference (c) original instance. reference wont updated automatically.

this demonstrates doing want:

dict = new dictionary<int,value>(); value v = new value() { hello = 1, bye = "qwerty"}; dict.add(1, v); value c = dict[1]; console.writeline(c.bye); dict[1] = new value() { hello = 2, bye = "asdf" }; console.writeline(dict[1].bye);//this line changed

so clarify, updating whole value per requirements.

just recommendation, might help explain end result trying achieve. there may much improve way go it.

c# .net dictionary reference-type

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -