VB.net:按条件设置属性“NULL”?

时间:2011-01-20 14:04:21

标签: vb.net object null properties

为什么下面的代码在VB.net 2008中有错误?

Dim Object1 As New Class1

Object1.SetId = If(rbSet.Checked = True, Convert.ToInt32(txtSetId.Text.Trim()), DBNull.Value)

我正在尝试的是通过条件设置对象的属性。

1 个答案:

答案 0 :(得分:2)

使用 Nothing

Object1.SetId = If(rbSet.Checked = True, Convert.ToInt32(txtSetId.Text.Trim()), Nothing)