Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multiple Criteria for Sorting Objects

Multiple Criteria for Sorting Objects

Scheduled Pinned Locked Moved C#
questioncsharpalgorithmsdata-structurestutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    What is the recommended way to sort arrays of objects in multiple ways in C#? For example, given an array of employee data objects you might want to sort this array by > employee name > salary > employment date > employment date, then salary at different places in your application. Paul

    D U 2 Replies Last reply
    0
    • L Lost User

      What is the recommended way to sort arrays of objects in multiple ways in C#? For example, given an array of employee data objects you might want to sort this array by > employee name > salary > employment date > employment date, then salary at different places in your application. Paul

      U Offline
      U Offline
      Utku KAYA
      wrote on last edited by
      #2

      Hi, If its not expensive to use a DataTable, DataTable has a static Sort() method and you can do all these by using thaty method. For two criterial sorts , you can call it again in the first modified table.

      1 Reply Last reply
      0
      • L Lost User

        What is the recommended way to sort arrays of objects in multiple ways in C#? For example, given an array of employee data objects you might want to sort this array by > employee name > salary > employment date > employment date, then salary at different places in your application. Paul

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        Create several classes (or a single one, with all the features you need) which implement IComparer. When you call Array.Sort, pass an instance of this class as the second parameter. Yes, even I am blogging now!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups