Martyn

Martyn Bullerwell's Blog

Simple Date Sort Class

This very simple class allows sorting of date when the object is added to a collection, such as an Array List.

using System;
using
System.Collections;
using
System.Text;

namespace
Adatis.Class
{
  class DateUpdatedSort : IComparable
  {

  private string _name;
  private DateTime _date;

  #region
Constructors

   public DateUpdatedSort()
   { }

   public DateUpdatedSort(string Name, DateTime DateUpdated)
   {
      this._name = Name;
      this._date = DateUpdated;
   }

#endregion


#region
Interface Methods

/// <summary>
/// The Method that must re refenced in order for this object to be sorted.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>

public int CompareTo(object obj)

{
    if(obj is DateUpdatedSort)
{

    DateUpdatedSort dus = (DateUpdatedSort)obj;
    return dus.UpdatedDate.CompareTo(this.UpdatedDate);

}
else
{
    throw new Exception("Object Not Correct type)";
}
}

#endregion

#region
Public Properties



/// <summary>
/// The name of Control
/// </summary>
public string Name
{

get {return _name;}
set {_name = value;}
}



/// <summary>
/// The Date Updated
/// </summary>
public DateTime UpdatedDate
{
  get { return _date; }
  set { _date = value;}
}

    #endregion

}
}