C# Check if object exists before referencing -
this question has answer here: what nullreferenceexception, , how fix it? 29 answers i wondering if there's way check if object exists before referencing @ all. not check if null because isn't working either. using epplus package read excel files , when gets index not have value data in it, sends exception. private datatable worksheettodatatable(string tablename) { excelsheet = excelworkbook.worksheets[tablename]; datatable dt = new datatable(); try { int totalrows = excelsheet.dimension.end.row; int totalcols = excelsheet.dimension.end.column; (int j = 1; j <= totalcols; j++) { dt.columns.add(); (int = 1; <= totalrows; i++) { if (j == 1) { dt.rows.add(); } try { ...