tacoyaggi 2024. 2. 2. 09:43

Base

'Base'는 파생 클래스 내에서 부모 클래스의 멤버에 엑세스하는데 사용 한다.

정적 메서드 안에서는 사용할 수 없다.

// 부모 클래스
public class Parent
{
    public string ParentName { get; set; }

    public string ParentMethod()
    {
        return "부모 메서드";
    }
}


// 자식 클래스
class Children : Parent
{
    public string ChildrenMethod()
    {
       base.ParentName = base.ParentMethod();

        return base.ParentName;
    }
}

결론

'Base' 키워드를 통해 해당 부모 클래스의 메서드 캡슐화 가능