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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:14:36+00:00 2026-05-26T02:14:36+00:00

I am implementing a class that in the style of the LINQ libraries has

  • 0

I am implementing a class that in the style of the LINQ libraries has an overload for a custom IComparer. (e.g. OrderBy: OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>) and OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>)).

I would like to implement the 2-argument overload in terms of the 1-argument overload. Something like the following:

T Method<T>(IEnumerable<T> collection, IComparer<T> comparer)
{
    // Do something that returns a T
}

T Method<T>(IEnumerable<T> collection) where T: IComparable<T>
{
    IComparer<T> comparer = /*what goes here?*/;
    return Method(collection, comparer);
}

In this respect, the question boils down to asking, how do I obtain an instance of IComparer for a type that implements IComparable?

  • 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-26T02:14:37+00:00Added an answer on May 26, 2026 at 2:14 am

    You are looking for Comparer<T>.Default.

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

Sidebar

Related Questions

I've got a project which has in it a protocol, a class implementing that
In Java I have the necessity of implementing a class that extends Thread within
I can't find any documentation on implementing a class that inherits System.Windows.Media.Brush - what
Given that a class actually is moveable , manually implementing the move constructor and
I am trying to create a class implementing the generic IComparer of my own
I'm implementing a Python ontology class that uses a database backend to store and
I'm implementing a class that talks to a motor controller over a USB device.
I have the following markup: <li id=fragment-3 class=slides virtualsation ui-tabs-panel style=> <h1>Virtualisation</h1> <p>By implementing
Suppose I have a custom collection class that provides some internal thread synchronization. For
I have a class that already has a 'natural' order, and wish to define

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.