将C#转换为VB.net - 语法快捷方式

Lig*_*ng3 0 c# vb.net

抱歉愚蠢的问题,但这有点烦人的事情.在c#我可以很快说:

new RolesController().SaveUserRole(Userid, cbxRoles.SelectedIndex);
Run Code Online (Sandbox Code Playgroud)

我不喜欢Long Version,而且SaveUserRole返回void:

RolesController rc = new RolesController()
rc.SaveUserRole(Userid, cbxRoles.SelectedIndex);
Run Code Online (Sandbox Code Playgroud)

问题是:在VB中可以做同样的事情 - "短版"吗?不低于版本......

Dim rc As New RolesController()
rc.SaveUserRole(Userid, cbxRoles.SelectedIndex)
Run Code Online (Sandbox Code Playgroud)

slo*_*oth 6

您必须使用该Call语句,因为表达式必须以标识符开头:

当被调用表达式不以标识符开头时,通常使用Call关键字.建议不要将Call关键字用于其他用途.

所以你的代码应该是这样的:

Call new RolesController().SaveUserRole(Userid, cbxRoles.SelectedIndex)
Run Code Online (Sandbox Code Playgroud)