【问题标题】:How to use `Me` in vb.net With...End With block如何在 vb.net 中使用 `Me` With...End With 块
【发布时间】:2014-08-13 04:52:03
【问题描述】:

使用此代码“VB.Net 2005”

Dim dep as new Department
With dep.AddNewEmployee()
   .FirstName = "Mr. A"
   .LastName = "B"
   If TypeOf {dep.AddNewEmployee()'s instance} is Serializable then
      'Do something
   End If
end With

{dep.AddNewEmployee()'s instance} 中是否有此代码的语法。

有可能吗?

【问题讨论】:

    标签: .net vb.net instance with-statement


    【解决方案1】:

    使用With 语法无法做到这一点。不过,您可以添加一个引用新对象的局部变量:

    Dim dep as new Department
    Dim emp = dep.AddNewEmployee()
    With emp
       .FirstName = "Mr. A"
       .LastName = "B"
       If emp.GetType().IsSerializable Then
          'Do something
       End If
    end With
    

    【讨论】:

      【解决方案2】:

      你可以试试这个方法:

      With dep.AddNewEmployee()
         .FirstName = "Mr. A"
         .LastName = "B"
         If .GetType().IsSerializable Then
            'Do something'
         End If
      end With
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-11-29
        • 2010-11-12
        • 2012-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-02
        相关资源
        最近更新 更多