C#

메서드 숨기기 - new 키워드 사용

이쥬우 2025. 1. 22. 11:50
728x90

new 키워드를 사용하여 부모 클래스의 메서드를 숨기고, 자식 클래스에서 새로운 메서드를 정의할 수 있습니다. 이 방법은 부모 클래스의 메서드를 재정의하는 것처럼 보이지만, 실제로는 부모 클래스의 메서드를 완전히 대체하지는 않습니다.

public class CustomGridView : DevExpress.XtraGrid.Views.Grid.GridView
{
    // new 키워드를 사용하여 GetRowCellValue 메서드를 숨김
    public new object GetRowCellValue(int rowHandle, string fieldName)
    {
        // 사용자 정의 로직 추가
        Console.WriteLine("Custom GetRowCellValue called!");

        // 부모 클래스의 메서드 호출
        return base.GetRowCellValue(rowHandle, fieldName);
    }
}
728x90