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

How to calculate SNR of signals in MATLAB? -

java - How to create Table using Apache PDFBox -

c# - Attempting to upload to FTP: System.Net.WebException: System error -