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 1436
感动是毒
感动是毒 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:15

    It means what it says.

    The "Count" method returns a value type. It's an integer. It will always have a value where it's default value is zero.

    Your check really should be:

    if (arrTopics.Count() != 0)
    

提交回复
热议问题