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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:22:00+00:00 2026-06-12T03:22:00+00:00

Is there a way to send a any method as a parameter? I need

  • 0

Is there a way to send a any method as a parameter? I need to do it for all kind of method, not caring about signatures and returns. Say something like this (bad code, just for the idea):

public class Foo
{
...
void TestMethod(DontKnowWhatToPutHere theDelegate) {}
...
}

...

foo.TestMethod(-foo.AnotherMethod(1,2)-);
foo.TestMethod(-foo.AnotherMethod("I don't care method signature nor returning type")-);

I tried with no success to do it with Action as parameter.

What I need to do is to send any method to a function, and then use reflection to get method name and parameters, so if there’s another way you guys can figure out, I would gladly hear about it too.

  • 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-06-12T03:22:01+00:00Added an answer on June 12, 2026 at 3:22 am

    No. The compiler always has to be able to identify a specific delegate to convert to, and there’s no single delegate type which is compatible with all method signatures. You can get a long way by using Action, Action<T>, Action<T1, T2> etc, then Func<TResult>, Func<T1, TResult> etc… but even that’s going to fail when it comes to out and ref parameters. Additionally, there’s overload resolution to consider.

    Additionally, your syntax is passing the result of a method invocation, which isn’t the same thing as passing a method in the first place. (That’s ignoring the - prefix/suffix, which appears to be made-up syntax.)

    What you could use is Expression<Action> and wrap the method call:

    void TestMethod(Expression<Action> action)
    {
        ...
    }
    

    Then:

    foo.TestMethod(() => foo.AnotherMethod(1,2));
    

    Within TestMethod you can then look into the expression tree to find out that it’s a method call, work out the target, the parameters etc. See the MSDN page on expression trees for more information.

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

Sidebar

Related Questions

is there any way to send whats in a text view (im trying to
Is there any way I can send an email, like any frameworks or something.
is there any way that when i user send an email to admin@xx.com the
I know that soap can send XML over http, is there any way to
I was wondering if there was any way through C# or C++ to send
Is there a way to send an extra parameter through a form in rails
Is there any way to add some args in the *args parameter of resque
I want to send the email for html page. Is there any method to
Is there a way to send multiple lines of text to the clipboard using
Is there a way to send -D directives to an android app? On desktop

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.