# 30.StringBuilder เพื่อนคู่ string

💬 ในรอบนี้เราจะมาดูชัดๆในเรื่องของความเป็น **Immutable** ของ string ว่าถ้าเราต่อ string ไปเรื่อยๆมันจะเกิดปัญหาอะไรขึ้นกับโปรแกรมเรา และเราจะแก้ไขปัญหานั้นยังไง ซึ่งก็ไม่เห็นต้องบอกเลยหัวเรื่องก็จั่วอยู่แล้วว่าเป็น **StringBuilder** ไงล่ะ

{% embed url="<https://www.youtube.com/watch?v=U3xy2uZUuiA&list=PLUjAn8nwWnijERZ3HpzBk7NfSrau74_lQ&index=49>" %}

## 🎯 สรุปสั้นๆ

### 👨‍🚀 การต่อ string ที่ไม่ซับซ้อน

{% hint style="danger" %}
**อย่าต่อโดยใช้เครื่องหมาย +**\
เน้นย้ำคำโตๆว่า **อย่างทำ!!** โปรแกรมไม่ได้พังหรอกแต่มันไม่เป็นโค้ดของพวก professional ทำกัน และโปรแกรมของเราจะช้าลงแบบไม่ควรจะเป็น
{% endhint %}

ถ้าเราต้องการต่อ string แบบไม่ได้ซับซ้อนอะไรแนะนำให้ใช้ **Placeholder** หรือไม่ก็ **Interpolation** แทนการใช้เครื่องหมาย + (ถ้าไม่รู้ว่ามันคืออะไรให้กลับไปดูบทก่อนหน้าซะ)

{% content-ref url="/pages/-Lmt\_11lffOoUeiTzEI2" %}
[29.ลงลึกกับ string](/beginner-1/csharp101/intermediate/string.md)
{% endcontent-ref %}

### 👨‍🚀 การต่อ string ที่ซับซ้อน

ให้ใช้คลาส **StringBuilder** เข้ามาช่วย จากตัวอย่างจะเห็นการใช้ CPU และความเร็วที่แตกต่างกันอย่างเห็นได้ชัดเลย (กดๆดูไปเถอะอุตส่าทำมาให้ดู + ไหนๆกดดูแล้วฝากกด subscribe กดไลค์กดแชร์ด้วยเน่อ)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.saladpuk.com/beginner-1/csharp101/intermediate/stringbuilder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
