dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
737 stars 1.57k forks source link

System.Linq doc snippets (\dotnet-api-docs\snippets\csharp\System.Linq #10110

Open DickBaker opened 4 months ago

DickBaker commented 4 months ago
  1. the LINQ docs C# samples consist of 7 projects to showcase IEnumerable and IQueryable unfortunately much code unnecessarily invokes AsQueryable() despite simpler IEnumerable method implementations existing [thus such guidance is poor as such AsQueryable() overhead can be avoided]
  2. should update to useful modern C# v12 semantics [Primary constructors, Collection expressions, Span, is, etc]
  3. calls being made to default parameterless ctor then assigning individual properties, rather than using parameterised ctors explicitly [or better yet primary constructor]
  4. current analyzers also disclose numerous Warnings/Messages, emphasising poor guidance for today's coding
  5. many cases of wastefully using Any(),Count(),LongCount etc when optimal coding available (e.g. Count, Length for Collections).
  6. spurious ToString() call in OrderByIComparer()

I will shortly submit a PR to explain problems & my suggestions.

dotnet-policy-service[bot] commented 4 months ago

Tagging subscribers to this area: @dotnet/area-system-linq