Wednesday, April 29, 2009

Convert a delimited string to an interger array


public static int[] ToIntArray(this string value, char separator)
{
return Array.ConvertAll(value.Split(separator), s=>int.Parse(s));
}

So we can do something like this:

int[] result = "1,2,3".ToIntArray(',');

No comments:

Post a Comment