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

  • Home
  • SEARCH
  • 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 823419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:56:40+00:00 2026-05-15T02:56:40+00:00

What is the best approach for sorting a generic list when one of its

  • 0

What is the best approach for sorting a generic list when one of its objects property is changed?

I have the following example to help explain what is needed.

public class Sending
{
    public Sending(int id, DateTime dateSent)
    {
        this.Id = id;
        this.DateSent = dateSent;
    }

    public int Id { get; set; }
    public DateTime DateSent { get; set; }
}

public class Operation
{
    public List<Sending> ItemsSent = new List<Sending>();

    public Operation()
    {
        ItemsSent.Add(new Sending(1, new DateTime(2010, 6, 2)));
        ItemsSent.Add(new Sending(2, new DateTime(2010, 6, 3)));

        ItemsSent[1].DateSent = new DateTime(2010, 6, 1);
    }
}

What is the best way to trigger a sort on the list to sort by date after the DateSent property is set? Or should I have a method to update the property and perform the sort?

  • 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-15T02:56:40+00:00Added an answer on May 15, 2026 at 2:56 am

    You could implement IComparable<Sending> on Sending and call Sort() on the ItemsSent. I would suggest to write a method to update an object and update the list manually.

    public class Sending: IComparable<Sending>
    {
      // ...
      public int CompareTo(Sending other)
      {
        return other == null ? 1 : DateSent.CompareTo(other.DateSend);  
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help me to find best approach for managing Backbone views. For example I have
What is the best approach to render a large number of 2D graphical elements
What is a best approach to make a function or set of statements thread
What is the best approach, simple string concatenation or string.format ? For instance, what
What's the best approach (industry standard) when another business needs to upload an XML
What is the best approach to managing NHibernate transaction using Autofac within web application?
What is the best approach to storing a group of global settings for a
How should I best approach drawing a scatter plot diagram in Cocoa?
What is the best approach in using a timer. Use a System.Timer.Timer class or
What is the best approach to do PreferencePage in eclipse?

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.