I have a string array. What is the simplest way to check if all the elements of the array are numbers
string[] str = new string[] { "23", "25", "Ho" };
If you add a reference to the Microsoft.VisualBasic
assembly, you can use the following one-liner:
bool isEverythingNumeric =
str.All(s => Microsoft.VisualBasic.Information.IsNumeric(s));
You can do this:
var isOnlyNumbers = str.All(s =>
{
double i;
return double.TryParse(s, out i);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With