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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:41:57+00:00 2026-05-26T01:41:57+00:00

I have a pieces of code: The method is as follows: public IEnumerable<c> Test(){

  • 0

I have a pieces of code:

The method is as follows:

public IEnumerable<c> Test(){
  var collection = new a();
  IEnumerable<c> bs = collection.Where(item => item.Id > 10).Select(item => item);
  return from item in collection
         where item.Id > 10
         select item;
}

(the first two lines compiles fine)

It doesn’t compile and fails with:

Cannot implicitly convert type System.Collections.Generic.IEnumerable<Stackoverflow.b> to System.Collections.Generic.IEnumerable<Stackoverflow.c>

however the code below compiles just fine:

return from item in collection
       where item.Id > 10
       select new b(null);

since the type of the expression in the select clause is the same I’d expect it to compile in both cases or fail in both.

if I use method syntax instead of query comprehesion and write:

collection.Where(item => item.Id > 10).Select(item => item)

that too compiles

my question is “Is there something wrong with the universe” (is this a compiler bug) or am I missing something?

EDIT

I have no using System.Linq so the normal select and where methods is not in play only those below
The code is part of an academic exercise to try and stretch the pattern-based method overload resolution of LINQ. The signatures are deliberately weird/surprising and the where includes a projection though I believe this would generally be a pretty bad idea.

EDIT

The definitions of the classes in question and the select extension method

public static class Enumerable {
    public static IEnumerable<c> Select(this IEnumerable<b> self, Func<b,b> selector){
        return null;
    }
}

public class a{
    public IEnumerable<b> Where(Predicate<a> predicate){
        return null;
    }
    public int Id { get; set; }
}

public class b{
}

public class c{
}
  • 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-26T01:41:57+00:00Added an answer on May 26, 2026 at 1:41 am

    That’s all about query expressions translation. You might want to look at C# Language Specification 4.0 7.16.2 (or 7.15.2 for C# 3.0) for more details, but in short, expressions like:

    
    from x in c
    where f(x)
    select x
    
    

    Are translated just to

    
    c.Where(x => f(x))
    
    

    so your Enumerable.Select wouldn’t be called and you’ll get IEnumerable<b> as a result instead of IEnumerable<c>. Exactly what compiler is complaining about.

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

Sidebar

Related Questions

I have the following two pieces of code: public class C { public void
I have pieces of code like this in a project and I realize it's
I have a pieces of code where i spawn off children processes to make
I have these two pieces of code, wich one is more readable? foreach decimal
I have two pieces of C++ code running on 2 different cores. Both of
In my Django templates, I have a couple pieces of code that are like
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have lots of small pieces of code that look like: for it in
I have been trying to figure out the best practices to write test-friendly code,
I have been trying to follow this example (download the source code from a

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.