.NET allows you to define types outside of a namespace, but this is generally not a good idea. Defining types within a namespace makes code easier to read and understand, and it helps minimize the risk of duplicating type names and definitions.
The following code shows an example of a duplicate type definition caused by having the definition outside of the namespace:
' VB
Public Class CreateDocument
' Code here
End Class
Namespace ClientDocs
Public Class CreateDocument
' Code here
End Class
End Namespace
// C#
public class CreateDocument
{
// Code here
}
namespace ClientDocs
{
public class CreateDocument
{
// Code here
}
}
' VB
Namespace ClientDocs
Public Class CreateCoverLetter
' Code here
End Class
Public Class CreateDesignDoc
' Code here
End Class
End Namespace
// C#
namespace ClientDocs
{
public class CreateCoverLetter
{
// Code here
}
public class CreateDesignDoc
{
// Code here
}
}