Skip to content

Instantly share code, notes, and snippets.

@Danielkaas94
Created January 29, 2018 18:20
Show Gist options
  • Save Danielkaas94/dd364de10bef4cb1c41f13a54780d5a5 to your computer and use it in GitHub Desktop.
Save Danielkaas94/dd364de10bef4cb1c41f13a54780d5a5 to your computer and use it in GitHub Desktop.
GetIntegersFromList & GetIntegersFromList2
public static IEnumerable<int> GetIntegersFromList(List<object> listOfItems)
{
// Believe 👍
List<int> integerList = new List<int>();
int content;
foreach (var item in listOfItems)
{
if (item is int)
{
int.TryParse(item.ToString(), out content);
integerList.Add(content);
}
}
return integerList;
}
public static IEnumerable<int> GetIntegersFromList2(List<object> listOfItems)
{
return listOfItems.OfType<int>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment