Perhaps a dumb question about strings and links in C #

Good afternoon,

Sorry if this question is too stupid, but I don’t know much (almost nothing) about the .Net memory management system, and I really need to clarify this doubt ... I have one Dictionary<String, Int32>that I need to use, and now I need a tree whose nodes marked with lines in the same dictionary. Since, of course, I do not want to store redundant information, how can I make sure that the node label points to the same links as the dictionary keys?

Many thanks,

+3
source share
3 answers

ARE strings are reference types, so this will be the default unless you do something to break it.

, asp.net( , ) , , , .

+4

- :

TreeNode node = new TreeNode();
node.Text = dictionary.Keys[0];

.

+3

Since String is a reference type, you must be very careful when referencing dictionary entries using references to String objects. You obviously can, but it is sometimes impossible (just like the other client-server links mentioned by Hans). If you know what you are doing, use links, but if not, you can always compare strings by value (the Equals method) refer to the elements of the dictionary.

+1
source

Source: https://habr.com/ru/post/1772660/


All Articles