Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
07-05 07:53
관리 메뉴

nomad-programmer

[Programming/C#] 분할 클래스 본문

Programming/C#

[Programming/C#] 분할 클래스

scii 2020. 9. 9. 17:49

분할 클래스(Partial Class)란, 여러 번에 나눠서 구현하는 클래스를 말한다. 분할 크래스는 그 자체로 특별한 기능을 하는 것은 아니고, 클래스의 구현이 길어질 경우 여러 파일에 나눠서 구현할 수 있게 함으로써 소스 코드 관리의 편의를 제공하는 데 그 의미가 있다.

using System;

namespace CSharpExample
{
    partial class MyClass
    {
        public void Method1()
        {
            Console.WriteLine("method1");
        }

        public void Method2()
        {
            Console.WriteLine("method2");
        }
    }

    // 클래스 이름이 등일해야 한다.
    partial class MyClass
    {
        public void Method3()
        {
            Console.WriteLine("method3");
        }

        public void Method4()
        {
            Console.WriteLine("method4");
        }
    }


    class MainApp
    {
        static int Main(string[] args)
        {
            MyClass obj = new MyClass();
            obj.Method1();
            obj.Method2();
            obj.Method3();
            obj.Method4();

            return 0;
        }
    }
}


/* 결과

method1
method2
method3
method4

*/
Comments