2

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)

When I call this from C# as such:

_obj.toggleExclusion(mouse, study)

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

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

C# 4 is where the optional arguments were added I believe.
1

A workaround would be to pass the optional argument - since it has a default, there is no loss if you just pass it.

1 Comment

If it's passed in it takes the passed in value, not the optional default. This works fine if the optional default happens to be default(T), but probably won't work if the default was 42. In that case the passed in value overrides it.
1

You might be able to use System.Reflection.Missing.Value. I am not sure if it works for a Visual Basic call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.