Namespaces are heavily used in C# programming in two ways. First, the .NET Framework uses namespaces to organize its many classes, as follows:
In C#, global namespace is the root namespace. The global::System will always refer to the namespace "System" of .Net Framework.
System.Console.WriteLine("Hello World!");
System is a namespace and Console is a class in that namespace. The using keyword can be used so that the complete name is not required, as in the following example:
using System;
Console.WriteLine("Hello");
Console.WriteLine("World!");
C# namespace example
Namespaces Overview
Namespaces have the following properties:
- They organize large code projects.
- They are delimited by using the
.
operator. - The
using directive
obviates the requirement to specify the name of the namespace for every class. - The
global
namespace is the "root" namespace:global::System
will always refer to the .NET Framework namespaceSystem
.
0 comments:
Post a Comment