在C#中,拼接字符串的方法有多种,其中最常用的方法是使用加号(+)或String.Concat方法。例如:
使用加号(+):string str1 = "Hello";string str2 = "World";string result = str1 + " " + str2;Console.WriteLine(result); // 输出:Hello World使用String.Concat方法:string str1 = "Hello";string str2 = "World";string result = String.Concat(str1, " ", str2);Console.WriteLine(result); // 输出:Hello World另外,还可以使用StringBuilder类来拼接大量字符串,以提高性能。例如:
StringBuilder sb = new StringBuilder();sb.Append("Hello");sb.Append(" ");sb.Append("World");string result = sb.ToString();Console.WriteLine(result); // 输出:Hello World 

