string is Immutable it means when we initialize a newly created string value it get stored in memory then if we assign some new value to same variable new value stored on new memory place and variable now refer this new memory place, old value still exist in memory.
If again assign a third value to same variable, again new value get stored on new memory location,
and variable refer it now, still previous two have existence.
Conclusion: value of string can't be update actually
string s = "Hello";
StringBuilder : Value of stringBuilder can be updated. So it is recommended to use for better performance.
StringBuilder s = new StringBuilder();
s = s.Append("Hello");
If again assign a third value to same variable, again new value get stored on new memory location,
and variable refer it now, still previous two have existence.
Conclusion: value of string can't be update actually
string s = "Hello";
StringBuilder : Value of stringBuilder can be updated. So it is recommended to use for better performance.
StringBuilder s = new StringBuilder();
s = s.Append("Hello");
No comments:
Post a Comment