List<string>里的集合和字符串互转

1.把List<string>里的集合转换成字符串:
  List<string> names =newList<string>(){"ccc","xxx","aaa","bbbb"};
  names.Sort();
  var result =String.Join(",", names.ToArray());
  Console.Write(result);


2.字符串怎样转为List<string>集合:
  string s = "1,2,3";
  List<string> list = new List<string>(s.Split(','));
  foreach (string t in list)
  {
    MessageBox.Show("*" + t + "*");
  }

 

posted @ 2021-12-29 15:13  醉酒三分醒  阅读(886)  评论(0编辑  收藏  举报