If I execute this line I create a string which is a reference.
string mystring = "Hello World"
Is variable mystring in the same context as the object I declare it? And the data "Hello World" on the heap?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Official Answer: it’s an implementation detail and you don’t need to know.
It is of course knowable for a specific (current) version of the framework:
if this is inside a method, then
mystringis a reference variable, usually on the stack. But when it is captured by a lambda, or when the method is async, or … it is moved to the heap.if this is inside a class, then each instance will contain a
mystringreference as a field, stored on the heap.In both cases there is an anonymous string object on the heap containing
"Hello World"