C# Namespaces

How to Use Namespaces?

To use a namespace in, you typically include the 'using' directive at the beginning of your code file.

The 'using' directive informs the compiler to look for types within the specified namespace.

                                                    
                                                    using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}
                                                    
                                                

Creating Custom Namespaces:

To create a custom namespace, you can define it using the 'namespace' keyword followed by the namespace name and its contents enclosed in curly braces {}.

                                                    
                                                    namespace MyNamespace
{
    public class MyClass
    {
        public void MyMethod()
        {
            Console.WriteLine("MyMethod called.");
        }
    }
}