0

我做了这个代码

(DataGridViewRow  dgRow in dgvMarksEntryForClass.Rows)
{
     if (dgRow.Cells["dgcolMarksObtain"].Value.GetType is decimal)
     {
         //some action
     }
     else { 
         //some action
     }
}

如何检查值是否

dgRow.Cells["dgcolMarksObtain"].Value.GetType

是十进制类型的吗?

4

3 回答 3

2

您可以使用十进制TryParse()方法。

(DataGridViewRow  dgRow in dgvMarksEntryForClass.Rows)
{
    Decimal cellValue;
    if (Decimal.TryParse(dgRow.Cells["dgcolMarksObtain"].Value, out cellValue)
    {
         //some action
    }
    else
    {
        //some action
    }
}
于 2013-09-06T07:31:41.513 回答
0
decimal value;
if(Decimal.TryParse(dgRow.Cells["dgcolMarksObtain"].Value.ToString(), out value))
  // It's a decimal
else
  // No it's not.
于 2013-09-06T07:35:49.363 回答
-2

尝试这个-

(DataGridViewRow  dgRow in dgvMarksEntryForClass.Rows)
{
     if (dgRow.Cells["dgcolMarksObtain"].Value.GetType() is decimal)
     {
         //some action
     }
     else { 
         //some action
     }
}
于 2013-09-06T07:38:33.860 回答