小技巧之一 string[]合并

 1             string[] str = new string[] { "111", "112" };          
 2             string temp = "";
 3             int i = 0;
 4             foreach (string docnum in str)
 5             {
 6                 if (i == str.Length - 1)
 7                 {
 8                     temp = temp + "" + docnum.Replace("'", "") + "";
 9                 }
10                 else
11                 {
12                     temp = temp + "" + docnum.Replace("'", "") + ",";
13                 }
14                 i++;
15             }

这段代码的主要作用是将一个String[]合并到String中,用于多个数同时传入SQL。如果换成下面的一行代码是否优雅一些呢?

string temp = String.Join(",", docNums).Replace("'", "");
原文地址:https://www.cnblogs.com/wonder223/p/3598486.html