Namespace

JunDev·2025년 2월 27일

C#

목록 보기
12/23

Namespace

In C#, a namespace is a container or a logical grouping used to organize and manage the code in a program. It helps avoid name conflicts by grouping related classes, interfaces, structs, enums, and delegates together.

// namespace (avoid clash between other variables and functions)
namespace dev1
{
    class MyClass
    {
        public static void SayHello()
        {
            Console.WriteLine("Hi!");
        }
    }
}

namespace user
{
    class Program
    {
        static void Main(string[] args)
        {
            dev1.MyClass.SayHello(); // output: Hi!
        }
    }
}

profile
Jun's Dev Journey

0개의 댓글