我有一个struct Test,它作为值添加到字典中。 我想要做的是按值的日期时间对字典进行排序。使用DateTime对象对值字典进行排序
struct Test
{
DateTime dt;
public string ID;
}
Dictionary<String, Test> dict = new Dictionary<String,Test>();
Test t = new Test();
t.dt = DateTime.Now;
t.ID = "XUDF";
dict.Add(t.ID, t);
t.dt = DateTime.Now.AddDays(17);
t.ID = "RFGT";
dict.Add(t.ID, t);
t.dt = DateTime.Now.AddDays(3);
t.ID = "ADLV";
dict.Add(t.ID, t);
t.dt = DateTime.Now.AddHours(2);
t.ID = "SKFU";
dict.Add(t.ID, t);
我不确定在此之后要做什么。 此外,这是最好的方式去呢? 我正在使用.net 3
我想要做的是有一个列表,我可以通过ID访问,但也由日期时间在t.dt中排序。 我希望能够通过它的ID选择一个对象,但也能够迭代并按照datetime的顺序出现。
也许你已经知道了:它不是C#字典,它是一个.NET字典。 –
...使用OrderedDictionary? –
为什么你想排序字典?我没有任何意义。你的意思是你想检索字典的所有值,按其成员之一的值进行排序? – Tipx