How can I create a var that doesn't get destroyed after exiting the method?
-
hi can you please tell me how can I create a local var that doesn't get destroyed after exiting the method? thanks
I'm a bit confused by your question, as objects become eligible for garbage collection when no references to them remain in the code. Could you provide specifics on what exactly you're trying to do? What kind of variable is this, and what do you plan on doing with it when the method returns?
-
hi can you please tell me how can I create a local var that doesn't get destroyed after exiting the method? thanks
-
I'm a bit confused by your question, as objects become eligible for garbage collection when no references to them remain in the code. Could you provide specifics on what exactly you're trying to do? What kind of variable is this, and what do you plan on doing with it when the method returns?
-
I am wondering if it's possible to create a variable in a method as follow: string tttt = "Gggg"; and then after exiting the method i can still access that var
-
hi can you please tell me how can I create a local var that doesn't get destroyed after exiting the method? thanks
Hello One of the main ideas of C# -if not the main- is being managed by the garbage collector. That's why they call it a managed code -while there is an unmanaged code-. This task is quite advanced and is concerned with memory locations. Even then you'd have to store the memory location -otherwise known as pointer- somewhere to access the value. You still can do something similar to that in C# with reference type only using WeakReference class. Revise it in your MSDN Yet again what's exactly your point? Sometimes something that's possible is not always the best solution for a matter!! I'm sure there is a better approach to solve your problem -if it's not a mere programming challenge of some sort- Regards:rose: