如何在vb.net中使用`Me` With ... End With块 [英] How to use `Me` in vb.net With...End With block

查看:169
本文介绍了如何在vb.net中使用`Me` With ... End With块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码"VB.Net 2005"

With this code "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

中的

该代码有任何语法.

in {dep.AddNewEmployee()'s instance} is there any syntax for this code.

有可能吗?

推荐答案

无法使用With语法来做到这一点.您可以只添加引用新对象的局部变量:

There is no way to do that by using the With syntax. You could just add a local variable that references the new object though:

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

这篇关于如何在vb.net中使用`Me` With ... End With块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆