CA1050: Declare types in namespaces
The following example shows a library that has a type incorrectly declared outside a namespace, and a type that has the same name declared in a namespace.
Imports System ' Violates rule: DeclareTypesInNamespaces. Public Class Test Public Overrides Function ToString() As String Return "Test does not live in a namespace!" End Function End Class Namespace GoodSpace Public Class Test Public Overrides Function ToString() As String Return "Test lives in a namespace!" End Function End Class End Namespace
The following application uses the library that was defined previously. Note that the type that is declared outside a namespace is created when the name Test is not qualified by a namespace. Note also that to access the Test type in Goodspace, the namespace name is required.