Why is List <T> .Count <= 0 worth it?
In many code snippets, I saw that the following condition is used to check for an empty list:
List<string> someList = someFunctionThatPopulatesAList();
if (someList == null || someList.Count <= 0)
return;
I am wondering - why not use the following condition:
if (someList == null || someList.Count == 0)
return;
Is there a case when List<T>.Countnegative?
+4
3 answers
: Any() - .
, Length <= 0 Length Length == 0.
. , - , .net List < > implementation, Length(). , , , , .
When using code analysis tools, this will allow the code analysis tool to know what
Lengthis of positive value and can improve the ability of the tool to conduct a full analysis of your code.
0