Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Redundant Select

ID: cs/linq/useless-selectKind: problemSecurity severity: Severity: warningPrecision: very-highTags:   - quality   - maintainability   - useless-code   - language-features   - external/cwe/cwe-561Query suites:   - csharp-security-and-quality.qls

Click to see the query in the CodeQL repository

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

Recommendation

Remove the redundant select method call.

Example

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

classRedundantSelect{staticvoidMain(string[]args){List<int>lst=Enumerable.Range(1,10).ToList();foreach(intiinlst.Select(e=>e).Where(e=>e%2==0)){Console.WriteLine(i);}}}

[8]ページ先頭

©2009-2025 Movatter.jp