Namespaces are used to provide a "named space" in
which your application resides, so A namespace is designed for providing a way
to keep one set of names separate from another. Namespaces
are heavily used in C# programming in two ways.
1.
First,
the .NET Framework uses namespaces to organize its many classes
2. Second, declaring your own namespaces can help you control
the scope of class and method names in a larger programming project.
Syntax
namespace namespace_name {
// code declarations
}
|
Full Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 // here consoleApplication1 is namespace
{
class ExceptionHandlingExampleProgram
{
static void Main(string[] args)
{
object o2 = null;
try
{
int i2 = (int)o2;
}
catch (Exception exceptionObj)
{
// log exception from exceptionObj
}
finally
{
// do cleanup work here
}
}
}
}
|