- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between String and StringBuilder in C#
Strings in C#
String is immutable in C# that would mean you couldn’t modify it after it is created. It creates a new object of string type in memory if you will perform any operation.
string str1 = "Welcome!"; // creates a new string instance str1 += "Hello"; str1 += "World”;
StringBuilder in C#
StringBuilder is mutable in C#. This means that if an operation is performed on the string, it will not create a new instance every time. With that, it will not create new space in memory, unlike Strings.
StringBuilder str1 = new StringBuilder(""); str1.Append("Welcome!"); str1.Append("Hello World!"); string str2 = str1.ToString();
Advertisements