티스토리 뷰

프로그램/C#

[Server Side] null 체크

서.라.연 2010. 10. 11. 11:17
-- 자주 사용하는 메서드이니 기억하자

    // null 체크  (decimal로 변경시 공백으로 들어갈 경우 convert가 되지 않으며 error가 나므로 0으로 변경한다.)
    public static decimal NullCheck(object d)
    {
        if (d == null || d == DBNull.Value || string.IsNullOrEmpty(d.ToString()))
            return 0;
        return Convert.ToDecimal(d);
    }

댓글