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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:57:10+00:00 2026-06-02T17:57:10+00:00

I can define a delegate and write the query like this. Func<string, bool> filter

  • 0

I can define a delegate and write the query like this.

Func<string, bool>   filter  = s => s.Length == 5;

IEnumerable<string> query = names.Where(filter)                                  
                                 .Select(x => x.ToUpper());

My question is, if the Func<T, TResult> is a delegate taking a string as argument and returning a bool, why cannot I say:

delegate bool D(string s);
D d = new D(delegate(string s) { return s.Length == 1; });

IEnumerable<string> query = names.Where(d).Select...

?

  • 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-02T17:57:12+00:00Added an answer on June 2, 2026 at 5:57 pm

    Because they are different types.

    A shorter version giving the same kind of error:

    delegate bool D(string s);
    delegate bool F(string s);
    
    D d = new D(delegate(string s) { return s.Length == 1; });
    F f = d;
    

    Error 1 Cannot implicitly convert type ‘Program.D’ to ‘Program.F’

    And the extension method Where is defined as

    Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
    

    So you need a Func<string, bool> and D is similar but not compatible.

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

Sidebar

Related Questions

In Python I can define a function as follows: def func(kw1=None,kw2=None,**kwargs): ... In this
I can define an event like this(declared function): MyElement.Keyup +=MyDeclaredFunction I can also define
I can define default value in domain by this way : class ProcessingPriority {
In core.php I can define Configure::write('Routing.admin', 'admin'); and /admin/controller/index will work. but if I
In the servlet 2.4 spec you can define dispatchers in the filter config [REQUEST
Given the following MSDN sample code, why can't I define the Action delegate inline:
I have seen people define their events like this: public event EventHandler<EventArgs> MyEvent =
I'd like to define a delegate that takes a couple of dates, an unknown
Hai Techies, in C#, how can we define the multicast delegate which accepts a
I can't understand why it is correct to define a delegate with weak pointer

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.