How to achieve the C# 'as' keyword for value types in vb.net?

后端 未结 6 2397
无人及你
无人及你 2020-12-15 10:20

Most of our development is done in vb.net (not my choice) and one frequently used code pattern uses an \'On Error GoTo\' followed by a \'Resume Next\' so that all database f

6条回答
  •  星月不相逢
    2020-12-15 10:40

    In VB 9.0, "IF" is a true coalescing operation equivalent to C#'s "??". Source MSDN:

    So you could use:

    oObject.Name = IF(oReader.Item("Name").Equals(DBNull.Value),string.Empty,DirectCast(oReader.Item("Name"), String))
    

提交回复
热议问题