Sunday, March 31, 2013

Convert a Comma Delimited String to an ArrayList in C#

In the previous post i had shown u how to Convert comma delimited string to Dictionary
Now i will show how to Convert comma delimited string to string array, is easy as shown below...

string Val = "a,b,c,d,e";

string[] myStringArray = Val.Split(',');

in the  same way converting comma delimited string to arraylist is also easy in a single line as shown below....

ArrayList myArrayList = new ArrayList();

//Method 2
ArrayList list = new ArrayList(Val.Split(','));
Out Put :

myArrayList[0] = a;
myArrayList[1] = b;
myArrayList[2] = c; 
myArrayList[3] = d;
myArrayList[4] = e;

No comments:

Post a Comment