Created
January 29, 2018 18:20
-
-
Save Danielkaas94/dd364de10bef4cb1c41f13a54780d5a5 to your computer and use it in GitHub Desktop.
GetIntegersFromList & GetIntegersFromList2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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