質問

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.

役に立ちましたか?

解決

more better if u use if else?

add this after if, may be help

else {
 return false;
}

他のヒント

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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top