什么是" :="运营商(VB).NET或有什么好处? [英] What is the " := " operator in (VB).NET or what is it good for?

查看:193
本文介绍了什么是" :="运营商(VB).NET或有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个不时,想知道它是什么。我曾尝试谷歌,但它过滤出从搜索的字符。我有几本书不引用它的。

I see this from time to time and want to know what it is. I did try google, but its filtering out the characters from the search. I have a few books that don't reference it either.

FWIW,我记得在帕斯卡尔是是赋值运算符。

FWIW, I remember in pascal that is was the assignment operator.

任何人都可以点我到MSDN或类似的网页?

Can anybody point me to the MSDN or similar page?

推荐答案

您可以使用:=语法通过名称来分配参数Sub或功能,而不是严格的位置。例如:

You can use the := syntax to assign the parameters to a Sub or Function by name, rather than strictly by position. For example:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TestRoutine(Y:="TestString", X:=12)
    End Sub

    Private Sub TestRoutine(ByVal X As Long, Optional Y As String = "")
        ' Do something with X and Y here... '
    End Sub

End Class

需要注意的是TestRoutine指定X作为第一个参数,和Y为第二,但在Form1_Load的呼叫有它们以相反的顺序,命名与每个参数:=运算符

Note that TestRoutine specifies X as the first parameter, and Y as the second, but the call in Form1_Load has them in the opposite order, naming each parameter with the := operator.

下面是一个链接,关于这个问题的MSDN文章:

Here's a link to an MSDN article on the subject:

<一个href="http://msdn.microsoft.com/en-us/library/51wfzyw0.aspx">http://msdn.microsoft.com/en-us/library/51wfzyw0.aspx

我没有看到这个经常使用,但在用Excel的宏记录器,它用它生成的VBA宏的很多

I don't see this used very often, except in VBA macros generated by Excel's macro recorder, which uses it a lot.

这篇关于什么是&QUOT; :=&QUOT;运营商(VB).NET或有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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