2013-10-29 34 views

回答

1

使用适当的索引:

public string selectCell(int Column, int Row) 
{ 
    if (CurrentTable.Rows.Count <= Row) // zero based indices 
     throw new ArgumentException("Invalid number of rows in selectCell", "Row"); 
    if (CurrentTable.Columns.Count <= Column) 
     throw new ArgumentException("Invalid number of columns in selectCell", "Column"); 
    var row = CurrentTable.Rows[Row]; 
    // remove following check if you want to return "" instead of null 
    // but then you won't know if it was an empty or an undefined value 
    if (row.IsNull(Column)) 
     return null; 
    return row[Column].ToString(); 
} 

您也可以使用输入Field extension method也支持可空类型,但因为你想用这种方法对所有字段,最好使用Object.ToString如图所示以上。

相关问题