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());
MessageBox.Show(s1 + "\r\n" + s2);
结果:1,2,,3
a,b,,c
字符串转List
这里s的分隔符不是“,”而是“, ”,后面有一个空格
string s = "1, 2, 3";
List
foreach (string t in list)
{
MessageBox.Show("*" + t + "*");
}
这里s的分隔符是“,”
string s = "1,2,3";
List
foreach (string t in list)
{
MessageBox.Show("*" + t + "*");
}
更多C# LIST和STRING互相转换相关文章请关注PHP中文网!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号