11,567 questions
Add an extension method:
namespace System
{
public static class StringExtensions
{
public static string SafeTrim(this string value, params char[] trimChars)
{
if (value == null)
{
return string.Empty;
}
else
{
return value.Trim(trimChars);
}
}
}
}
Update your IF condition as below:
if (list != null &&(list.flight_iata.SafteTrim().ToLower().Contains(searchBar.Text.ToLower()) || list.status.SafteTrim().ToLower().Contains(searchBar.Text.ToLower())))
The SafeTrim() method will return a string.Empty if the specified string is null.
If right, please Accept.
Enjoy Programming!!!