Saturday, October 24, 2015

String Vs StringBuilder

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");

No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...