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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:04:10+00:00 2026-05-25T02:04:10+00:00

Purpose: To have multiple options to sort using properties of my class . I

  • 0

Purpose: To have multiple options to sort using properties of my class .
I managed to sort using samAccountName using Comparable but failed to correctly implement IComparer. But know I am getting an error specified below.

Error:Does not implement interface member System.Collections.Icomparer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ActiveDirectory
{
    public class sortLastName : IComparer
    {
        int IComparer.CompareTo(Employee oEmployee, Employee oEmployee2)
        {
            return String.Compare(oEmployee.lastName, oEmployee2.lastName);
        }
        public static IComparer sortYearAscending()
        {
            return (IComparer)new sortLastName();
        }

    }
//The code works great when I make a call like 
// List<Employee> x = new List<Employee>();
// x.sort();// sorts by samAccountName
// Now I would like to figure out how to sort by lastName and still be able to sort by 
//samAccountName if necceaary. 
    public class Employee :IComparable
    {
        //default sort order
        public int CompareTo(object oEmployee)
        {
            Employee emp1 = (Employee)oEmployee;
            return String.Compare(this.samAccountName, emp1.samAccountName);
        }



        public string lastName
        {
            get;
            set;

        }

          public string samAccountName
        {
            get;
            set;
        }
    }
}
  • 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-25T02:04:10+00:00Added an answer on May 25, 2026 at 2:04 am

    you need to implement a method named “Compare” not “CompareTo” for your sortLastName-class implementing IComparer

    then you can sort by x.Sort with this overload:

    x.Sort(new sortLastName());
    

    this is the implementation you should use:

    public class sortLastName : IComparer<Employee>
    {
        public int Compare(Employee oEmployee, Employee oEmployee2)
        {
            return String.Compare(oEmployee.lastName, oEmployee2.lastName);
        }
    }
    

    (Note I didn’t change the name because you wouldn’t see the context any more but sortLastName is no good name for a comparer)

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

Sidebar

Related Questions

To have a general-purpose documentation system that can extract inline documentation of multiple languages,
I have seen this macro defined before but never really knew its purpose. Can
We are using Oracle Weblogic 10.3 as our application server. We have multiple modules
Using Wordpress I have created a multiple select box so that users can select
so i am developing my own download manager for educational purpose. I have multiple
I have C++ class with multiple parents; each parent defines a function with a
Is possible create (register) a new class in runtime using delphi. I have a
I have a menu in my WPF application with multiple options which act like
I have an entity called Client, and each Client can have multiple Properties. CoreData
I have a form that has multiple fields, and for testing purposes is there

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.