Why am I getting “CS0472: The result of the expression is always true since a value of type int is never equal to null of type int?”

后端 未结 9 1426
感动是毒
感动是毒 2020-12-20 12:09
string[] arrTopics = {\"Health\", \"Science\", \"Politics\"};

I have an if statement like:

 if (arrTopics.Count() != null)
<         


        
9条回答
  •  死守一世寂寞
    2020-12-20 12:28

    Like the error says, int can never be null. I'd change the code to

    if (arrTopics != null && arrTopics.Any())
    

    Or even more efficient if you know arrTopics is an array and never null is

    arrTopics.Length != 0
    

提交回复
热议问题