
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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();
- Related Articles
- Difference between StringBuffer and StringBuilder.
- Difference between StringBuilder and StringBuffer in Java
- What is the difference between String, StringBuffer and StringBuilder classes in Java explain briefly?
- What is the difference between StringBuffer and StringBuilder in java?
- What is the difference between a StringBuffer and StringBuilder in java?
- Java String, StringBuffer and StringBuilder Tutorial.
- Converting String to StringBuilder in Java
- Replace a string using StringBuilder
- Difference between String and StringBuffer.
- Difference between String buffer and String builder in Java
- Converting a StringBuilder to String in Java
- Difference between string and StringBuffer in Java.
- What is the difference between String and string in C#?
- Difference Between Character Array and String
- Difference between string and char[] types in C++

Advertisements