欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c# List<int> 转 string 以及 string [] 转 List<int>

程序员文章站 2022-04-24 14:25:31
...

List<int> 转 string :

list<int>: 1,2,3,4,5,6,7  转换成字符串:“1,2,3,4,5,6,7”

List<int> list= new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
string depaid = string.Join(",", list);

string 转 List<int>:

string s = "1, 2, 3";
List<string> list = new List<string>(s.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries));
List<string> list = new List<string>(s.Split(','));//或者

 List<string> 转 List<int>

var listOfStrings =(new[]{"4","5","6"}).ToList();
var listOfInts = listOfStrings.Select<string,int>(q =>Convert.ToInt32(q));

List<int> 转List<string> 

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

C#中string[]数组和list<string>:

System.String[] str={"str","string","abc"};
List<System.String> listS=new List<System.String>(str);

从List<System.String>转到System.String[]

List<System.String> listS=new List<System.String>();
listS.Add("str");
listS.Add("hello");
System.String[] str=listS.ToArray();

c#中从string数组转换到int数组

int[] output = Array.ConvertAll(input , int.Parse);
相关标签: list转换 泛型