List to string, separated by commas
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( ));
MessageBox.Show(s1 + "rn" + s2);
Result: 1,2,,3
a,b,,c
String to List
The delimiter of s here It's not "," but ", ", followed by a space
string s = "1, 2, 3";
List
foreach (string t in list)
{
MessageBox.Show("*" + t + "*");
}
The delimiter of s here is ","
string s = "1,2,3";
List
foreach (string t in list)
{
MessageBox.Show( "*" + t + "*");
}
For more articles related to the conversion of C# LIST and STRING, please pay attention to the PHP Chinese website!