I have a string array that contains... well, strings, some of which are numbers. I am looking to sum only the numbers from the string, using LINQ.
I came up with this:
var array = new string[] { "asd", "asd", "53", null, "51", "asd" };
int sum = array.Where(x => int.TryParse(x, out _)).Select(x => int.Parse(x)).Sum();
However I am wondering if there is a way to, sort of, unite the Where and Select clauses somehow?
Thanks!