I have a method right now that loops through a list of business objects name Properties has a Serial # or not. If I find a Serial #, I exit the loop and return true, otherwise I return false.
Code is as follows:
public bool HasSerialNumber()
{
if (this.Properties != null && this.Properties.Count > 0)
{
foreach (var property in Properties)
{
if (!string.IsNullOrEmpty(property.SerialNumber))
return true;
}
}
return false;
}
Is there a better LINQ approach to this?
I have the following in mind:
return Properties.Where(x => !string.IsNullOrEmpty(x.SerialNumber)).ToList().Count > 0;
Is there a better/faster method for checking for non empty string?