List轉字串,用逗號隔開
List
list.Add("a");
list.Add("b");
list.Add ("c");
//MessageBox.Show(list.);
//LoadModel();
string s = string.Join(",", list.ToArray());
MessageBox.Show(s) ;
List
list.Add(new test("1", "a"));
list.Add(new test("2", " b"));
list.Add(new test("", ""));
list.Add(new test("3", "c"));
var a = from o in list select o. test1;
var b = from o in list select o.test2;
string s1 = string.Join(",", a.ToArray());
string s2 = string.Join(",", b.ToArray(string s2 = string.Join(",", b.ToArray( ));
MessageBox.Show(s1 + "rn" + s2);
結果:1,2,,3
a,b,,c
a,b,,c
a,b,c
不是“,”而是“, ”,後面有一個空格
string s = "1, 2, 3";
List
foreach (string t in list)
{
MessageBox.Show("*" + t + "*");
string s = "1,2,3";
List
foreach (string t in list)
{
"*" + t + "*");
}
更多C# LIST和STRING互相轉換相關文章請關注PHP中文網!