C# 数组、集合和字符串之间的相互转换

字符串转为数组

string str = "1,2,3,4";

string[] strArr = str.Split(',');

 

数组转为字符串

string[] scoresArr = { "1", "2", "3", "4", "5" };
string scores = string.Join(",", scoresArr);

 

字符串转为集合

string str = "a,b,c";

List<string> strList = str.Split(',').ToList();

 

集合转为字符串

List<string> abcList = new List<string> { "a", "b", "c", "d" };
string str = string.Join(",", abcList);

posted @ 2021-03-01 15:26  黑夜的宠儿  阅读(3199)  评论(0编辑  收藏  举报