Use Any() in place of Count() to prevent enumerating

This rule flags the Count and LongCount LINQ method calls used to check if the collection has at least one element. These method calls require enumerating the entire collection to compute the count. The same check is faster with the Any method as it avoids enumerating the collection.
pull/5493/head
Qstick 2 years ago
parent 738dc2c98c
commit 4fe9daec03

@ -194,7 +194,6 @@ dotnet_diagnostic.CA1819.severity = suggestion
dotnet_diagnostic.CA1822.severity = suggestion dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1823.severity = suggestion dotnet_diagnostic.CA1823.severity = suggestion
dotnet_diagnostic.CA1824.severity = suggestion dotnet_diagnostic.CA1824.severity = suggestion
dotnet_diagnostic.CA1827.severity = suggestion
dotnet_diagnostic.CA1829.severity = suggestion dotnet_diagnostic.CA1829.severity = suggestion
dotnet_diagnostic.CA1834.severity = suggestion dotnet_diagnostic.CA1834.severity = suggestion
dotnet_diagnostic.CA1839.severity = suggestion dotnet_diagnostic.CA1839.severity = suggestion

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Common.OAuth namespace NzbDrone.Common.OAuth
{ {
@ -16,7 +17,7 @@ namespace NzbDrone.Common.OAuth
{ {
var parameters = this.Where(p => p.Name.Equals(name)); var parameters = this.Where(p => p.Name.Equals(name));
if (parameters.Count() == 0) if (parameters.Empty())
{ {
return null; return null;
} }

Loading…
Cancel
Save