Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:12:38+00:00 2026-05-16T03:12:38+00:00

It is my understanding that it is not possible to have an optional parameter

  • 0

It is my understanding that it is not possible to have an optional parameter in a delegate in the version of VB that ships with VS2008.

However, I am wondering if there are any workarounds or plans for incorporating this feature into VB.NET in the future?

What I’d like to do:

Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, optional ByRef BufferPosition As Integer = 0) As T 

'Implementation of a func that matches the delegate'
Class A
  Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
  ....

In the absence of specifying “optional” inside the actual delegate itself, it’d at least be nice to be able to do it in the function implementation only:

Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, ByRef BufferPosition As Integer) As T 

'Implementation of a func that matches the delegate'
Class A
  Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
  ....

At least this second way, the functions for the delegate will always have a value mapped to each parameter, although some may come from the function side and not the calling side.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:12:39+00:00Added an answer on May 16, 2026 at 3:12 am

    Instead of trying to write a delegate signature that handles all the cases I am interested in, and possibly limiting future flexibility (though it really depends on the case..), I sometimes use an Action (delegate who’s signature takes no parameters) instead of writing my own delegate:

    void SomeFunction(Action action)
    {
        // ...
        action();
    }
    

    There is a feature in C# (and I’m pretty sure in VB) that allows you to include values from the local scope, rather than passing them as parameters. It is called an anonymous delegate. In general CS terms, taking local values with you, rather than passing them as a parameter, is one form of what is called a closure.

    int someValueFromLocalScope = 5;
    SomeFunction(() => DoSomethingElse(someValueFromLocalScope));
    
    // you can also assign a closure to a local variable:
    
    int someValueFromLocalScope = 5;
    Action doSomethingElse =
        delegate()
        {
            DoSomethingElse(someValueFromLocalScope);
        }; // Or you could use () => { } syntax...
    SomeFunction(doSomethingElse);
    

    Then, SomeFunction doesn’t need to know what parameters apply to the specific action.

    More info about Action: (the answer is about closures, but this may be helpful too)

    Action is simply a delegate that takes zero parameters, and returns zero values:
    http://msdn.microsoft.com/en-us/library/system.action.aspx

    Just like any other delegate, you can also use Action as a member variable.

    There are more pre-designed delegates:

    Action<TFirstParameter>
    Func<TReturnValue>
    Func<TFirstParameter, TReturnValue>
    

    etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.