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 1439
感动是毒
感动是毒 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:32

    What are you trying to ask here?

       Array.Count() returns an int which will never be null.
    

    If you want to know if the Array has been initialised then:

       if(arrTopics !=null) ...
    

    if you want to know if it's been initialised but has no members then:

      if(arrTopics.Count() > 0) ...
    

提交回复
热议问题