← back to index

S3903 — Types should be defined in named namespaces

Language: C#  |  Type: BUG  |  Severity: Major

Why is this an issue?

Types are declared in namespaces in order to prevent name collisions and as a way to organize them into the object hierarchy. Types that are defined outside any named namespace are in a global namespace that cannot be referenced in code.

Noncompliant code example

public class Foo // Noncompliant
{
}

public struct Bar // Noncompliant
{
}

Compliant solution

namespace SomeSpace
{
    public class Foo
    {
    }

    public struct Bar
    {
    }
}

or alternatively in C#10 and above

namespace SomeSpace;
public class Foo
{
}

public struct Bar
{
}