Creating Namespaces
Creating a namespace is easy. Just use the word namespace followed by the name. The contents of a namespace are enclosed in curly braces. The following example shows how to create a namespace and add a class to it.
namespace SAMS { using System; using aFilePerm = System.Security.Permissions.FileIOPermissionAccess; public class FilePerm { aFilePerm fileAccess = new aFilePerm(); public FilePerm() { fileAccess = aFilePerm.NoAccess; } public aFilePerm FileAccess { get { return fileAccess; } set { fileAccess = value; } } } }
The first line shows that this code is in the SAMS namespace. The next example shows how to access this class from another class.
using System; using aFilePerm = System.Security.Permissions.FileIOPermissionAccess; ...
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.