---
title: "Sort an ArrayList with DateTime using C#"  
description: "Sort an ArrayList with DateTime using C#"  
author: "Madam Walker"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1612/sort-an-arraylist-with-datetime-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Sort an ArrayList with DateTime using C#

I need to sort the [ArrayList](https://www.mindstick.com/articles/11973/arraylist-class-in-c-sharp) based on the StartDate available in the [system](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) which is a [DateTime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) variable.

```
public int id { get; set; }
public string name {get; set;}
public bool isAnctive { get; set; }
public string start { get; set; }
public string end { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public string Location { get; set; }
public string Description { get; set; }
```

Can someone please [enlighten me](https://answers.mindstick.com/qa/37702/could-someone-enlighten-me-on-the-loop-quantum-gravity-theory). I tried .Sort() but it just doesn’t do anything (its dump to try sort on ArrayList which has [objects](https://www.mindstick.com/forum/145447/what-are-objects) I know)

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by Anonymous User

Try by creating comparere like as below

```
public class ComparerDateTime : IComparer
{
    public int Compare(object x, object y)
    {
        MYCLASS X = x as MYCLASS;
        MYCLASS Y = y as MYCLASS;

        return X.date.CompareTo(Y.date);
    }
}

 MYCLASSList.Sort(new ComparerDateTime ());
```


---

Original Source: https://www.mindstick.com/forum/1612/sort-an-arraylist-with-datetime-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
