SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
C#

C# static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your C# code

  • All rules 493
  • Vulnerability46
  • Bug88
  • Security Hotspot24
  • Code Smell335

  • Quick Fix 61
Filtered: 30 rules found
confusing
    Impact
      Clean code attribute
        1. "Trace.WriteLineIf" should not be used with "TraceSwitch" levels

           Code Smell
        2. Generic logger injection should match enclosing type

           Code Smell
        3. Extensions should be in separate namespaces

           Code Smell
        4. Methods should not have identical implementations

           Code Smell
        5. Property names should not match get methods

           Code Smell
        6. Method signatures should not contain nested generic types

           Code Smell
        7. Collection sizes and array length comparisons should make sense

           Bug
        8. A conditionally executed single line should be denoted by indentation

           Code Smell
        9. Objects should not be disposed more than once

           Code Smell
        10. Parameter names should not duplicate the names of their methods

           Code Smell
        11. "params" should not be introduced on overrides

           Code Smell
        12. Composite format strings should be used correctly

           Code Smell
        13. Exceptions should not be explicitly rethrown

           Code Smell
        14. "abstract" classes should not have "public" constructors

           Code Smell
        15. Variables should not be checked against the values they're about to be assigned

           Code Smell
        16. Loggers should be named for their enclosing types

           Code Smell
        17. Methods should not return constants

           Code Smell
        18. "private" methods called only by inner classes should be moved to those classes

           Code Smell
        19. Ternary operators should not be nested

           Code Smell
        20. "params" should be used on overrides

           Code Smell
        21. "GC.SuppressFinalize" should not be invoked for types without destructors

           Code Smell
        22. Types should not have members with visibility set higher than the type's visibility

           Code Smell
        23. Fields that are only assigned in the constructor should be "readonly"

           Code Smell
        24. Methods without side effects should not have their return values ignored

           Bug
        25. Test classes should contain at least one test case

           Code Smell
        26. "sealed" classes should not have "protected" members

           Code Smell
        27. "for" loop increment clauses should modify the loops' counters

           Code Smell
        28. Loops with at most one iteration should be refactored

           Bug
        29. Tests should not be ignored

           Code Smell
        30. Redundant pairs of parentheses should be removed

           Code Smell

        "abstract" classes should not have "public" constructors

        consistency - conventional
        maintainability
        Code Smell
        • confusing

        Why is this an issue?

        How can I fix it?

        More Info

        The abstract modifier in a class declaration is used to indicate that a class is intended only to be a base class of other classes, not instantiated on its own.

        Since abstract classes cannot be instantiated, there is no need for public or internal constructors. If there is basic initialization logic that should run when an extending class instance is created, you can add it in a private, private protected or protected constructor.

          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube Community BuildAnalyze code in your
          on-premise CI
          Available Since
          9.1
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Sonar helps developers write Clean Code.
        Privacy Policy | Cookie Policy | Terms of Use