如何在VB功能中添加可选参数/默认值参数? [英] How to add an optional parameters/default value parameters in VB function?
本文介绍了如何在VB功能中添加可选参数/默认值参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Visual Basic中创建一个具有可选参数的方法?
How can I create a method that has optional parameters in it in Visual Basic?
推荐答案
使用Optional
关键字并提供默认值.可选参数必须是最后定义的参数,以避免创建歧义函数.
Use the Optional
keyword and supply a default value. Optional parameters must be the last parameters defined, to avoid creating ambiguous functions.
Sub MyMethod(ByVal Param1 As String, Optional ByVal FlagArgument As Boolean = True)
If FlagArgument Then
'Do something special
Console.WriteLine(Param1)
End If
End Sub
这样称呼:
MyMethod("test1")
或者像这样:
MyMethod("test2", False)
这篇关于如何在VB功能中添加可选参数/默认值参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文