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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:05+00:00 2026-05-23T12:19:05+00:00

[code] private static IOrderedEnumerable<Film> OrderBy(this IEnumerable<Film> source, Func<Film, object> order, bool desc) { if

  • 0

[code]

private static IOrderedEnumerable<Film> OrderBy(this IEnumerable<Film> source, Func<Film, object> order, bool desc)
{
    if (desc) { return source.OrderByDescending(order); }
    return source.OrderBy(order);
}

[Situation]

Ofcourse, linq already implements a order by. I’m only trying to generize it more. Mostly just to learn things, it doesn’t really add things other then that I can order by normally or order by descending with the same property.

[Question]

However I wish to make it more generic. Currently it only takes IEnumerable<T> and return IOrderedEnumerable<T> (where T currently is a movie. Custom model).
Is there any general type of list, enumerable or something that covers all List, IEnumerable IOrderedEnumerable etcetc?

  • 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-23T12:19:05+00:00Added an answer on May 23, 2026 at 12:19 pm

    Yes, there is. It’s IEnumerable<T>.

    Classes like List<T> implement the IEnumerable<T> interface, so a method that takes IEnumerable<T> can be used with most any collection.


    You forgot to specify the generic parameter to the method: OrderBy<Film>.

    The original OrderBy method also have a generic parameter for the type of the key. You might also want to use that, to make sure that the comparisons work properly, and that it doesn’t do a lot of unnecessary boxing and unboxing:

    private static IOrderedEnumerable<Film> OrderBy<Film, Key>(this IEnumerable<Film> source, Func<Film, Key> order, bool desc) {
      if (desc) { return source.OrderByDescending(order); }
      return source.OrderBy(order);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code compiles: private static void Main(string[] args) { bool? fred = true; if
Resharper just prompted me on this line of code: private static bool shouldWriteToDatabase =
I have this piece of code in c#: private static void _constructRow(SqlDataReader reader, system.IO.StreamWriter
This isn't valid code: public class MyClass { private static boolean yesNo = false;
This is Oliver Hanappi 's static reflection code he posted on stackoverflow private static
This is the code: private static void CreateCounter() { if (PerformanceCounterCategory.Exists(DemoCategory)) PerformanceCounterCategory.Delete(DemoCategory); CounterCreationDataCollection ccdArray
I have this code: private static void saveMetricsToCSV(String fileName, double[] metrics) { try {
I have this code private static Set<String> myField; static { myField = new HashSet<String>();
Enerjy has a problem with this line of code: private static List<ParseTree> getTestTrees(Xml test)
This is my code: private static final String CREATE_VISIT_TABLE = create table + VISIT_TABLE

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.