Use List.ConvertAll instead of LINQ#15140
Conversation
|
Do we have performance results before and after for this? cc @daxian-dbw |
|
@TravisEz13 In general, there's not a large performance difference between the two approaches. Using private List<int> list = Enumerable.Repeat(10, 10).ToList();
public List<string> Linq()
{
return list.Select(t => t.ToString()).ToList();
}
public List<string> ConvertAll()
{
return list.ConvertAll(t => t.ToString());
}https://gist.github.com/xtqqczze/22cfeb3eb34e4ca21f4af87adf4956a5
|
|
Format working group can you review the change? |
|
I wonder why do you fix only one place? I found some more with |
The analyzer I used only found 1 instance of the pattern: All the other locations seem to be |
Ok :-) |
|
It seems it does not cover array. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Maintainers reviewed and agreed to merge this. |
|
🎉 Handy links: |
PR Summary
PR Context
https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1.convertall
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).