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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:19:17+00:00 2026-05-17T15:19:17+00:00

Just for testing reasons, I defined my own Where-Method for Linq like so: namespace

  • 0

Just for testing reasons, I defined my own Where-Method for Linq like so:

namespace Test
{
    public static class LinqTest
    {
        public static IEnumerable<TSource> Where<TSource>(
                        this IEnumerable<TSource> source,
                        Func<TSource, bool> predicate)
        {
            return new List<TSource> { };
        }
    }
}

So if I use a query like this, I never get a result:

    var test = new string[]{ "a", "b", "c" };
    var x = from y in test
            where y.Length > 0
            select y;
    foreach (var element in x)
        Console.WriteLine(element);

My question is: How does the compiler know which extension method is supposed to be called? The one included in LINQ, or the user-defined one?

Cheers,
Chris

  • 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-17T15:19:17+00:00Added an answer on May 17, 2026 at 3:19 pm

    The rules for extension method are similar to those for normal method call lookup. The short version is the compiler will find all of the methods and extension methods which of the name which are accessible and choose the best match among those (with non-extension methods being preferred over extension methods).

    Just like normal methods though the choice of which extension method to use can be ambiguous. This would be the case here if both System.Linq and Test namespaces were used within the application. Based on your information it sounds like the test namespace is not referenced with a using hence it won’t be considered and the Linq version wins out.

    Note: The above is a summary of how lookup occurs and is by no means definitive. The C# language spec is the authority here and covers it in much greater detail.

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

Sidebar

Related Questions

I have been looking at using TDD and implementing proper testing (only just started
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I'm just getting into unit testing, and have written some short tests to check
I'm just getting started with learning about Unit testing (and TDD in general). My
I'm new to RhinoMock's just been doing state unit testing up till now. How
I am just starting out with DI & unit testing and have hit a
I've just started doing some PowerShell scripting, and I'm running into a problem testing
For various reasons (questioning the reasons is not helpful to me), I'd like to
If I define a class with a private default constructor and a public constructor
I just inherited some code which makes me uneasy: There is a testing library,

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.