How does .Net saves string variables whose value is same? For example,
string str1 = “xyz”;
string str2 = “xyz”;
Another scenario is,
string str1 = str2 = str3 = “xyz”;
Will there be a single memory location for both of them or two different memory location?
I was asked about question in one of my recent interviews. As per my understanding, I answered, when value is same then there will be single memory allocated to this value and both str1 and str2 will point to this memory location. Same will happen in second scenario mentioned in the question. But, interviewer was not convinced. Anyone any thoughts on this?
