首页 > 代码库 > C#中string和List<string>的相互转换

C#中string和List<string>的相互转换

C#中string和List<string>的相互装换:

List<string> list=new List<string>();

string str="";

listTostr:

    str=string.Join(‘,‘,list.ToArray());  //以","存在于str中

    如:list=("1","2","3");==>str="1,2,3"

strTolist:

    list=str.Split(‘,‘);   //以","进行断开

    如:str="A,B,C";==>list=("A","B","C");

 

C#中string和List<string>的相互转换