Question

I am using this filter in my AutoCompeteBox.

bool SearchBird(string search, object value)
        {
            if (value != null)
            {
                AllBirds datasourceValue = value as AllBirds;
                string name = datasourceValue.primary_language;

                if (name.ToLower().StartsWith(search.ToLower()))
                return true;

            }
            // If no match, return false. 
            return false;
        } 

Everything is working well when all entries have some value, but when there is any empty record it's crushing giving an error with null exception (which is understandable as there is no value). Tried do smth with extra if or else statement but still getting the same error.

Was it helpful?

Solution

more better if u use if else?

add this after if, may be help

else {
 return false;
}

OTHER TIPS

I've done that like that.

if (value != null)
            {
                AllBirds datasourceValue = value as AllBirds;
                string name = datasourceValue.primary_language;

                if (name == null)
                    return false;

                if (name.ToLower().StartsWith(search.ToLower()))
                return true;

            }
            // If no match, return false. 
            return false;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top