×

c# list

C# List之间的转换

匿名 匿名 发表于2020-07-22 08:17:38 浏览10 评论0

抢沙发发表评论

List<string> 转换为 string

1
2
3
4
5
6
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
list.Add("c");
string str = string.Join("  ", list.ToArray()); //用空格串联字符串
结果:a b c

 List<string> 转 List<int>

var list = (new[]{"1","2","3"}).ToList();
var newlist = list.Select<string,int>(x =>Convert.ToInt32(x));


 List<int> 转 List<string>

List<int> list = new List<int>(new int[] { 1,2,3 } );
List<string> newList = list.ConvertAll<string>(x => x.ToString());


群贤毕至

访客