使用可选参数创建函数 [英] Create function with optional parameters

查看:87
本文介绍了使用可选参数创建函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想用可选参数创建下面的VB代码功能

Hi All,

I want to create a function as below VB Code with optional parameters

Sub FIND_BTN(frm As Form, strTable As String, strCode As String, strDesc As String, ctlCode As String, Optional ctlDesc As Variant, _
    Optional vConn As Variant, Optional vFilter As Variant, Optional vDb As Variant, Optional Title As Variant, Optional ctlTo As Variant, _
    Optional ctlToDesc As Variant, Optional idx As Integer = -1, Optional fpsCtrl, Optional CodeCol As Long, Optional DescCol As Long)



请帮忙.



Please help.

推荐答案

从.NET 4开始,您可以创建
命名和可选参数 [
As from .NET 4 you can make
Named and Optional Arguments[^]in method. Try read this link. Perhaps it can help you?


自.Net Framework 4.0发布以来,C#支持可选参数.有关详细信息,请查看Kim Togo链接.
Since .Net Framework 4.0 released, C# supports optional parameter.For detail just look Kim Togo link.


金的答案:

在v.4.0之前,获得带有默认值的可选参数的唯一方法是方法重载.
方法如下:

In addition to the answer by Kim:

Before v.4.0, the only way of getting the effect of optional parameters with default was method overloading.
Here is how:

const int DefaultB = 13;

//...

void MethodWithOptionalArguments(int a, int b, string c) { /*...*/ } // full parameter list

void MethodWithOptionalArguments(int a, int b ) { // shortened list
   MethodWithOptionalArguments(a, b, string.Empty);
}
void MethodWithOptionalArguments(int a) { // even shorter
   MethodWithOptionalArguments(a, DefaultB, string.Empty);
}



—SA



—SA


这篇关于使用可选参数创建函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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