C#

C#

Made by DeepSource

Length-like property is compared against values which always evaluate to the same result CS-W1090

Bug risk
Critical

Length-like properties are usually used to "count" the number of elements. For example, in the context of an array, Length tells us the number of elements in the array. Comparing this property against 0 using the < or >= operators is meaningless and will always evaluate to false and true respectively. This comparison is likely a mistake and should be rewritten meaningfully.

Bad Practice

// Expression is always true.
if (arr.Length >= 0)
{
    // ...
}

// Expression is always false.
if (arr.Length < 0)
{
}

Recommended

if (arr.Length > 0)
{
    // Array is not empty
}