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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:13+00:00 2026-05-28T04:04:13+00:00

This is a noob question. So if I misstate the question, it’s because I

  • 0

This is a noob question. So if I misstate the question, it’s because I am not fully understanding what is happening.

Issue

Compile error:
Cannot implicitly convert type ‘MyClass.Items’ to ‘System.Collections.Generic.List’

Context

I am in iterating a List through an IOrderedEnumerable, but I am unable to return the desired record because it is of typed List (since my whole app is passing List objects back and forth).

My input to the method is a List, but it seems to be implicitly cast to IEnumerable when I use the OrderBy option.

I have read everything I’ve found, but it all seems to boil down to:

// ToList is not available!
return SingleItemToCheck.ToList;

or

// same type conversion error
List<Items> ReturningList = SingleItemToCheck;

The Problem Code

public static List<Items> FindCheapestItem(List<Items> source)
{
    // Now we pop only the first one. 
    // ISSUE: Sometimes the top entry on the list is bad, 
    //        so we need to check it!
    var BestItemCandidate = source.OrderBy(s => s.ItemDesirability);
    bool ForgetThisOne = false;

    foreach (var SingleItemToCheck in BestItemCandidate)
    {
        ForgetThisOne = false;

        // ... test for ItemDesirability, truncated
        if (Desirability < 0)
        {
            ForgetThisOne = true;
        }

        if (!ForgetThisOne)
        {
            // we are just returning the first desirable row
            // because we are sorted on desirability
            // and consuming code can only digest a single item.
            return SingleItemToCheck;  // !!! ARGH, compile error !!!
        }
    }

    // means we looped through everything and found nothing of interest
    return null;
}
  • 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-28T04:04:14+00:00Added an answer on May 28, 2026 at 4:04 am

    SingleItemToCheck is a single item, it is not a list. It does not have a ToList() method available. Simply create a list with that single item.

    return new List<Items> { SingleItemToCheck };
    

    Or if you’re only ever interested in the one item, change the return type of the method to simply Items and omit the list entirely.

    Another way to write that, particularly if you’re only interested in the one item, is to simply refactor the inner loop logic to a function and then write a query

    return source
             .OrderBy(s => s.ItemDesirability)
             .Where(s => IsDesirable(s)) // refactored loop logic, returning boolean
             .FirstOrDefault(); // first desirable item, or null
    

    Otherwise, if you absolutely need a list, but only one item in it, consider

     var list =  source
             .OrderBy(s => s.ItemDesirability)
             .Where(s => IsDesirable(s))
             .Take(1)
             .ToList();
    

    If no elements pass, this will be an empty list. You can then elect to return null, as your present code does, or return the empty list and let the callers deal with that instead of the null result.

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

Sidebar

Related Questions

Sorry if this is a noob question, but All my code is error-free and
Sorry because this is a noob question. I'm new with MySQL: I wrote a
I know this is a noob-ish question but is it possible to fully center
This kind of seems like a noob question, but I could not find an
This is a noob question from someone who hasn't written a parser/lexer ever before.
I know this may be a noob question, but it's bugging the heck out
Apologies if this is a slightly noob question, but looking to clarify my thoughts
i think this is a bit of a noob question, but here goes. I
Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
This is a question from a Java noob. I have eclipse open (JRE 1.6),

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.