使用 C# 调用调用带有可选参数的 Visual Basic 函数 [英] Calling a Visual Basic function with optional parameters with a C# call

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

问题描述

我正在使用客户端C# 与不同层上的 Visual Basic 代码进行交互 程序.Visual Basic 函数签名如下所示:

I am interacting with Visual Basic code on a different tier, using a client-side C# program. The Visual Basic function signature looks like this:

Public Sub toggleExclusion( _
    ByVal mouse As Double, _
    ByVal study As Integer, _
    Optional ByVal box As Integer = 0)

当我从 C# 中调用它时:

When I call this from C# as such:

_obj.toggleExclusion(mouse, study)

我收到一条错误消息,提示没有重载的 toggleExclusion 方法需要两个参数.为什么?

I get an error saying no overloaded method of toggleExclusion takes two arguments. Why?

推荐答案

这取决于 C# 版本.较旧的 C# 版本尚不支持可选参数 - 您始终需要指定所有参数.由于也支持 C# 4 可选参数.

That depends on the C# version. Older C# versions don’t yet support optional arguments – you always need to specify all of them. Since C# 4 optional arguments are supported, too.

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

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