Hi bonk,
a simple List collection may be good enough for what you need, it has a
sort method which will sort the items any way you like and allow for
duplicates. For example, in the code below the list is sorted in ascending
chronological order for the CreationTime values of the items in the list:
using System;
using System.Collections.Generic;
namespace Application1
{
class Thing
{
private DateTime creationTime;
public Thing(DateTime creationTime)
{
this.creationTime = creationTime;
}
public DateTime CreationTime
{
get
{
return this.creationTime;
}
}
}
class Program
{
static void Main(string[] args)
{
List<Thingitems = new List<Thing>();
Thing t1 = new Thing(new DateTime(2006, 12, 21));
Thing t2 = new Thing(new DateTime(2006, 12, 19));
Thing t3 = new Thing(new DateTime(2006, 12, 24));
Thing t4 = new Thing(new DateTime(2006, 12, 21));
items.Add(t1);
items.Add(t2);
items.Add(t3);
items.Add(t4);
//Sort the items by their creation time
items.Sort(delegate(Thing a, Thing b)
{
return a.CreationTime.CompareTo(b.CreationTime);
});
}
}
}
Mark
--
http://www.markdawson.org http://themightycoder.spaces.live.com
"bonk" wrote:
Ist there a collection that holds its data sorted (i.e. inserts items
sorted) AND allows to have duplicate values (by wich is sorted) ?
I would like to store elements in that collection wich should be sorted
by its Property "CreationTime" of type DateTime, where two or more
elements can habe the same CreationTime. Whenever I acess the list I
want to get its items sorted by CreationTime.