Câu hỏi phỏng vấn C#
Câu hỏi

What is the difference between string and StringBuilder in C#?

Câu trả lời

Here is the difference between string and StringBuilder in C#:

String

  • Strings in C# are immutable, meaning once a string is created, its value cannot be changed.
  • When you modify a string, a new string object is created in memory and the old one is discarded.
  • Strings are allocated on the heap and are thread-safe.
  • Strings are efficient for small amounts of text that don't change frequently.

StringBuilder

  • StringBuilder is a mutable string type that allows you to modify the contents of a string without creating a new object.
  • It is optimized for appending, inserting, or removing characters from a s...
junior

junior

Gợi ý câu hỏi phỏng vấn

senior

What is the use of conditional preprocessor directive in C#?

expert

Explain when to use Finalize vs Dispose ?

senior

What is Marshalling and why do we need it?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào