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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:55:25+00:00 2026-05-17T19:55:25+00:00

If I attempt to write two overloads of a method, one accepting an Expression<Func<T>>

  • 0

If I attempt to write two overloads of a method, one accepting an Expression<Func<T>> parameter and another accepting a Func<T>, I will get a compiler error on trying to call the method with a lambda expression because the two signatures create ambiguity. The following would be problematic, for example:

Method(() => "Hello"); // Is that a Func<string>,
                       // or is it an Expression<Func<string>>?

I get that. But I don’t like the approach of just accepting an Expression<Func<string>>, as this forces calling code to use a lambda expression. What if I want to be able to accept a method group as well?

My basis for asking this question is that I’m working on some code where I’d like to be able to write something like this:

Method(() => "Hello");

…and get output like this:

Executed '() => "Hello"' and got "Hello" back.

Meanwhile, I’d like to be able to do this as well:

Method(ReturnHello);

…and get output like this:

Executed 'ReturnHello' and got "Hello" back.

Is there any way to do what I’m trying to do here, without just using two different method names (e.g., ExpressionMethod and FuncMethod)? I realize that wouldn’t be such a big deal; I’m just curious if there’s another way.

  • 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-17T19:55:26+00:00Added an answer on May 17, 2026 at 7:55 pm

    You can overload a method to take either a Func<T> or Expression<Func<T>> but when you do that the automatic type determination fails so you need to explicitly define the types via casting. Like this:

    public static void Test()
    {
        Test((Func<string>)(() => "helllo"));
        Test((Expression<Func<string>>) (() => "hello"));
    }
    
    public static void Test<T>(Func<T> func)
    {
    
    }
    
    public static void Test<T>(Expression<Func<T>> expression)
    {
    
    }
    

    It’s not pretty.

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

Sidebar

Related Questions

When I attempt to open a file to write, I get an error: Ada.IO_Exceptions.Name_Error
There are two sql queries, I want to write as one query. the second
I would like to write an algorithm that compares one memory block with another
Suppose my attempt to write a pickle object out to disk is incomplete due
This is my first attempt to write shorthand if statements however am befuddled by
I'm trying to write a Date class in an attempt to learn C++. I'm
_SH_DENYWR denies any other attempt to open a file with write permissions (share violation)
I have two different PHP files that both write to the same file. Each
I am trying to write a fragment program that will take a texture and
First, a little background (greatly simplified): I have two classes, one called Entity and

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.