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 728795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:43:21+00:00 2026-05-14T06:43:21+00:00

Some predefined methods contain a ParamArray in their signature. Delegates, however, cannot contain a

  • 0

Some predefined methods contain a ParamArray in their signature.
Delegates, however, cannot contain a ParamArray in their signature.

Question: Assume you wish to create a delegation mechanism for a specific method which requires a ParamArray. How would you work around this constraint?

EDIT: just to make clear, assume you cannot change the method signatures themselves (pre-defined methods, defined by some 3rd party, be it Microsoft or not).

EDIT2: The real deal here is keeping the syntax sugar, because the following code does work, but eliminates the sugar:

Public Delegate Sub MyDelegate(ByVal myArgs() As Object)

Public Sub PredefinedSub(ByVal ParamArray myArgs() As Object)
    '...'
End Sub

Sub Test()
    Dim aDelegate As New MyDelegate(AddressOf PredefinedSub)
    aDelegate.Invoke(New Object() {1, 2, 3, 4})
End Sub

EDIT3: It turns out that Skeet’s solutions is applicable also for creating Events and Operators containing a ParamArray.

  • 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-14T06:43:22+00:00Added an answer on May 14, 2026 at 6:43 am

    Hmm… it works in C#:

    using System;
    
    class Test
    {
        delegate void Foo(params string[] args);
    
        static void Main()
        {
            Foo f = x => Console.WriteLine(x.Length);
    
            f("a", "b", "c");
        }
    }
    

    However, you’re right – the equivalent delegate declaration in VB fails:

    Delegate Sub Foo(ParamArray ByVal args() As String)
    

    Gives:

    error BC33009: ‘Delegate’ parameters cannot be declared ‘ParamArray’.

    Curious. Fortunately, there’s a way round it:

    Imports System
    
    Public Class Test
    
        Delegate Sub Foo(<[ParamArray]()> ByVal args() As String)
    
        Public Shared Sub Main()
            Dim f As Foo = AddressOf PrintLength
            f("a", "b", "c")
        End Sub
    
        Private Shared Sub PrintLength(ByVal x() As String)
            Console.WriteLine(x.Length)
        End Sub
    
    End Class
    

    Basically I’ve just applied ParamArrayAttribute manually. Seems to work fine.

    However, none of this would have stopped you from using existing ParamArray methods anyway. Those methods are quite capable of taking normal arrays – so you could have declared your delegate types as normal and still created delegate instances which referred to those methods with no problems at all. The delegate type only affects how you would be able to call the delegate.

    Other than declaring a delegate type with a parameter array, I don’t really see what the issue was.

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

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Tiny bug is that you are using incorrect quotes in… May 15, 2026 at 3:08 pm
  • Editorial Team
    Editorial Team added an answer You need to do your processing before you bind the… May 15, 2026 at 3:08 pm
  • Editorial Team
    Editorial Team added an answer On your onkeydown script code copy the id of the… May 15, 2026 at 3:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.