c# - Passing a "reference" to Dictionary element? -


so have:

concurrentdictionary<string, int> dict; 

i want pass reference 1 of elements, suppose dict["x"] method, , allow method change/set element. possible that, or have pass dictionary itself? also, possible if element not exist key in dictionary? or has valid key contained in dictionary?

yes, using delegate. delegate can called within changing function. delegate change or set key/value inside dictionary.

void dochangemyelement<t>(action<t> changeit) {     changeit(123); } 

you can call method with:

concurrentdictionary<string, int> dict = new ...; dochangemyelement(value => dict["x"] = value); 

Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

Delphi interface implements -

java - How to create Table using Apache PDFBox -