CodeQL documentation

Redundant Select

ID: cs/linq/useless-select
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - maintainability
   - useless-code
   - language-features
   - external/cwe/cwe-561
Query suites:
   - csharp-security-and-quality.qls

Click to see the query in the CodeQL repository

Passing an identity function to LINQ’s Select method (either explicitly or implicitly) yields a sequence that is the same as the one on which Select was called - such a call is redundant.

Recommendation

Remove the redundant select method call.

Example

In this example the call to the Select method has no effect and can be removed.

class RedundantSelect
{
    static void Main(string[] args)
    {
        List<int> lst = Enumerable.Range(1, 10).ToList();

        foreach (int i in lst.Select(e => e).Where(e => e % 2 == 0))
        {
            Console.WriteLine(i);
        }
    }
}
  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy