Pattern: Use of Count
instead of IsEmpty
Issue: -
The Count
or Length
property or the Count<TSource>(IEnumerable<TSource>)
extension method was used to determine whether or not the object contains any items by comparing the value to 0
or 1
, and the object has a more efficient IsEmpty
property that could be used instead.
Example of incorrect code:
class Test
{
ConcurrentQueue<int> _queue;
public bool HasNoItems => _queue.Count == 0;
}
Example of correct code:
class Test
{
ConcurrentQueue<int> _queue;
public bool HasNoItems => _queue.IsEmpty;
}