Partial Type
정의
- 클래스나 구조체, 인터페이스 또는 메서드의 정의를 둘 이상의 소스 파일로 분할할 수 있다.
- 각 소스 파일에는 형식이나 메서드 정의가 들어있고 이 모든 부분은 응용 프로그램을 컴파일할 때 “결합”된다.
장점
- 클래스를 개별 파일로 분할하면 여러 프로그래머가 동시에 작업을 수행할 수 있다.
기본형식
- 두 개의 클래스는 컴파일 할 때 결합되어 실행 된다.
public partial class PartialType
{
public void PartialTest1()
{
}
}
public partial class PartialType
{
public void PartialTest2()
{
}
}
- 밑의 선언은 “public class PartialType : FirstClass, FirstInterface{}, SecondInterface{}” 와 같다.
public partial class PartialType : FirstClass, FirstInterface{}
{
public void PartialTest1()
{
}
}
public partial class PartialType : SecondInterface{}
{
public void PartialTest2()
{
}
}
public partial class PartialType
{
int operandA;
int operandB;
public PartialType(int operandA, int operandB)
{
this.operandA = operandA;
this.operandB = operandB;
}
}
public partial class PartialType
{
public void Print()
{
Console.WriteLine("operandA :" + operandA + "operandB :" + operandB);
}
}
class Main
{
static void Main(string[] args)
{
PartialType patial = new PartialType(12,23);
patial.Print();
}
}
출력 결과
a : 12 b : 23
- partial을 명시한 클래스가 서로 결합되어 컴파일 된 것을 알 수 있다.
'Programming > C#' 카테고리의 다른 글
C# Lamda (0) | 2016.02.25 |
---|---|
C# Yield (0) | 2016.02.25 |
C# NullType (0) | 2016.02.18 |
C# Anonymous Method (0) | 2016.02.18 |
C# Generic (0) | 2016.02.18 |