Loading

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

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();

 

posted @ 2012-12-22 12:32  chear  阅读(32280)  评论(1编辑  收藏  举报