开发者

How can I use generic here

I am trying to use generic for the first time and trying to typecast my result returned from database to programmer defined data type. How can I do this.

dsb.ExecuteQuery("DELETE FROM CurrencyMaster WHERE CurrencyMasterId="
        + returnValueFromGrid<int>(getSelectedRowIndex(), "CurrencyMasterId"));

private T returnValueFromGrid<T>(int RowNo, string ColName)
{
    return Convert.ChangeType(dgvCurrencyMaster.R开发者_如何学Cows[RowNo].Cells[ColName].Value, T);
}


You're trying to use T as a value - you want the type T represents, and then you'll need a cast as well:

object value = dgvCurrencyMaster.Rows[RowNo].Cells[ColName].Value;
return (T) Convert.ChangeType(value, typeof(T));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜