I want to pass input as numbers separated by a comma (,) in a method which return true or false. The method DoesInputContainsNumbers should return true if all are numbers and return false if any of them are non numbers. For example, the input "20, 10, 30, 40" return true while the input "10, 20,aaa" return false. Is there a better way to achieve this than the below I tried?
public static bool DoesInputContainsNumbers(string input)
{
if (string.IsNullOrWhiteSpace(input))
{
return false;
}
try
{
input.Split(",").Select(x => int.Parse(x)).ToList();
}
catch (Exception ex)
{
return false;
}
return true;
}