본문 바로가기

C#

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

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

'C#' 카테고리의 다른 글

SOAP 통신  (0) 2025.01.22
DataTable 자식 행 유무 확인하기  (0) 2025.01.09
StackTrace 출력하기  (0) 2024.11.13
[Winform] 유저 컨트롤에 속성 추가  (0) 2024.04.25
Passing Output parameters to stored procedure using dapper  (0) 2024.04.24