When getting substring in .Net, does the new string reference the same original string data or does
Posted
by Elan
on Stack Overflow
See other posts from Stack Overflow
or by Elan
Published on 2010-03-18T22:36:29Z
Indexed on
2010/03/18
22:41 UTC
Read the original article
Hit count: 325
Assuming I have the following strings:
string str1 = "Hello World!";
string str2 = str1.SubString(6, 5); // "World"
I am hoping that in the above example str2
does not copy "World", but simply ends up being a new string that points to the same memory space only that it starts with an offset of 6 and a length of 5.
In actuality I am dealing with some potentially very long strings and am interested in how this works behind the scenes for performance reasons. I am not familiar enaugh with IL to look into this.
© Stack Overflow or respective owner