C# .NET: Convert a Comma Delimited String of Ints to a List of Ints Using LINQ

7/24/2014 8:59:12 PM

One line conversion of an appsettings comma delimited string of integers into a list of integers (List<int>).

The below code is in two lines to show that the string Ids are coming from the AppSettings.

string stringProductIds = System.Configuration.ConfigurationManager.AppSettings["ProductIds"];
List<int> productIds = stringProductIds.Split(new char[] { ',' }).Select(int.Parse).ToList();