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 1425
感动是毒
感动是毒 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:24

    Because Count method always returns integer if no elements in array it will return 0 other wise it will return number of elements. So what you need to do is just instead != null make it != 0 or > 0

提交回复
热议问题