C# when I declare a new instance of a class, and I modify the properties of it, how does it affect the original instance? via /r/learnprogramming


C# when I declare a new instance of a class, and I modify the properties of it, how does it affect the original instance?

Example:

public class DictionaryInit_BS { public Dictionary<int, DictionaryCheckup> C = new Dictionary<int, DictionaryCheckup>() { {100030, new DictionaryCheckup {theGrouping="C"}}, {100033, new DictionaryCheckup {theGrouping="C"}}, }; public Dictionary<int, DictionaryCheckup> E = new Dictionary<int, DictionaryCheckup>() { {105000, new DictionaryCheckup {theGrouping="E"}}, {110302, new DictionaryCheckup {theGrouping="E"}}, }; } 

So I have a class of Dictionaries.

In order to access this, I have to call it like this:

 TheClass = new DictionaryInit_BS(); 

Now, if for example I modify the values of TheClass like..

 TheClass.E = null; 

The E dictionary in the class is now null, but what is the state of DictionaryInit_BS.E ? Is it the original dictionary?

I'm going to assume this is the case.

So if my intention is to modify all of the values of the class above permanently how do I go about doing this such that when I restart the program, DictionaryInit_BS.E would be whatever I set it to? (Since I would need to declare an instance of that class to use it, there's no possibility of permanence, is there?)

Submitted July 11, 2017 at 03:12AM by Vendredi46
via reddit http://ift.tt/2uM8S10

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s