Tuesday, February 14, 2012

Convert string array to list in c#

Title:How to Convert string array to generic list in asp.net using c#.net

As in previous articles we have seen the data type conversions.Now i would like to give an example on how to convert the string array to List .To elaborate the example i have used a string "strs".Then it will split and store into array "StrArray".Finally the array is convert to list using below peace code and assign to list details List.
string strs = "1,1,3,4";
List detailsList;
string[] StrArray = strs.Split(',');
int[] intArray = Array.ConvertAll(strArray, new Converter(Convert.ToInt32));
detailsList = intArray.ToList();
Dim strs As String = "1,1,3,4"
Dim detailsList As List
Dim StrArray__1 As String() = strs.Split(","C)
Dim intArray As Integer() = Array.ConvertAll(strArray, New Converter(Convert.ToInt32))
detailsList = intArray.ToList()
Post a Comment