VB.NET 中的 := (冒号等于)有什么作用? [英] What does a := (colon equals) in VB.NET do?
问题描述
可能的重复:
:= 语法的用途是什么?
我尝试在 VB.NET 中搜索 :=
的 MDSN 文档,并搜索 Google 只链接到一个死的 MSDN 页面... :=
的目的是什么?
I've tried hunting down the MDSN documentation for :=
in VB.NET as well as scoured Google only to be linked to a dead MSDN page... What would the purpose of :=
be?
推荐答案
它强命名参数,允许您以不同于方法定义中指定的顺序调用带有参数的方法.
It strongly names arguments, allowing you to call a method with arguments in an order other than that specified in the method definition.
例如:
sub foo (byval x As Long, byval y As Long)
debug.print (String.Format("{0}, {1}", x.ToString, y.ToString))
end Function
可以通过使用它们的名称颠倒参数的顺序来调用:
can be called with the order of the arguments reversed by using their names:
foo (y:=999, x:=111)
印刷品:
111, 999
当您有很长的可选参数列表时,这尤其有用,您只想指定其中的几个,并且您想要指定的不是第一个.
This is especially useful when you have a long list of optional arguments, you only want to specify a few of them, and those that you want to specify are not the first ones.
这篇关于VB.NET 中的 := (冒号等于)有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!