-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix S6602 FP: FirstOrDefault is faster than Find in .NET 9 #9664
Comments
Maybe this rule for code targeting .NET 8.0 or below, and a new rule |
Note that A rule to change |
Hello @marco-carvalho, Thank you for pointing this out. Have a great day! |
According to dotnet/runtime#108064 and dotnet/runtime#65572 (comment) , it is deliberate that The idea is that if performance really matters, one should not use a method that takes a delegate. If One special case may be As a result, S6605 and similar Sonar rules should not recommend anything about methods on If corresponding methods on Regarding older versions of .NET, it is likely that code targeting .NET 5/6/7/8 or .NET Core will be migrated to .NET 9 or newer at some point; for .NET Framework, it might be less likely. |
Hello,
The rule S6602, which suggests using
Find
instead ofFirstOrDefault
, may no longer be applicable for projects targeting .NET 9.0.Recent benchmarks indicate that starting with .NET 9.0,
FirstOrDefault
is actually faster thanFind
. Below are the benchmark results.Code:
Results:
The text was updated successfully, but these errors were encountered: