Convert string with integers into an int array

11/8/2010 4:43:33 PM

Comma separated list of integers converted into an int array using C# and LINQ.

  int[] numbers = stringWithIds.Split(',').Select( s => Convert.ToInt32(s) ).ToArray();    // and with removing "empty" values    int[] numbers = stringWithIds.Split(separator).Where(s => s.Trim().Length > 0).Select(s => Convert.ToInt32(s)).ToArray();