---
title: "几种String拼接方式性能对比"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/csharp-string-concat-performance-comparison/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/02-编程语言与运行时/.NET与CSharp/几种String拼接方式性能对比.md"
content_hash: aa73950f0e1c5f73932d550f76879bad442ded9d8989386ba366ee66a9bf6fa5
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# 几种String拼接方式性能对比

﻿# 几种String拼接方式性能对比

> 创建时间：2021/12/10 11:47

* 几种String拼接方式性能对比

## 几种String拼接方式性能对比

```csharp
string str1 = &quot;test&quot;;
string str2 = &quot;test&quot;;

```

![assets/0024 - 几种String拼接方式性能对比__resource-001-cd046ea0b011.png](/media/96a5f67ffbc50ebd310d.png)

使用C#原生的System.Text中的接口：

`$"{x}:{y}"` 性能最差

string.Concat与string.Format 性能相似

复用StringBuilder的方式性能较高

Zstring的几种方式性能都最好，且堆内存分配量相同。
