Reference variables aready initialized
-
I'm looking for a way using C# or VB.net to reference variables. More specificly, I have a loaded hashtable that was created on my main form. When I open a new form, I need to have access to that information in the hastable. I don't want to pass the table between forms as this would create copies of the original and end up using more memory. What is the best way to accomplish this??
-
I'm looking for a way using C# or VB.net to reference variables. More specificly, I have a loaded hashtable that was created on my main form. When I open a new form, I need to have access to that information in the hastable. I don't want to pass the table between forms as this would create copies of the original and end up using more memory. What is the best way to accomplish this??
No it wont take up much memory! If you pass your HashTable to another form only a reference to that single HashTable is passed. So the memory usage is just 4 byte (on a 32 bit os). This also means changing the HashTable in one place also changes it everywhere else you passed the reference to. If you still dont want to pass the HashTable around and you only need one instance of it in your whole application declare the variable in your main form public static. This way everyone can access it with
MyMainFormClassName.MyPublicHashTableVariable
. -
I'm looking for a way using C# or VB.net to reference variables. More specificly, I have a loaded hashtable that was created on my main form. When I open a new form, I need to have access to that information in the hastable. I don't want to pass the table between forms as this would create copies of the original and end up using more memory. What is the best way to accomplish this??
KaptinKrunch wrote: don't want to pass the table between forms as this would create copies of the original and end up using more memory. Except for value types, everything in .NET is an object (and even value types can be boxed to be objects). All objects are already passed as references. That's why you don't need pointers, or * to dereference a pointer, and that's why you don't need new and delete--the GC keeps track of the references to an object. Marc MyXaml Advanced Unit Testing YAPO
-
No it wont take up much memory! If you pass your HashTable to another form only a reference to that single HashTable is passed. So the memory usage is just 4 byte (on a 32 bit os). This also means changing the HashTable in one place also changes it everywhere else you passed the reference to. If you still dont want to pass the HashTable around and you only need one instance of it in your whole application declare the variable in your main form public static. This way everyone can access it with
MyMainFormClassName.MyPublicHashTableVariable
.Thanks for the advise!!