如何对此数组进行排序 [英] How to sort this array

查看:69
本文介绍了如何对此数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


人是一个哈希表,我将其转换为数组。


人[] aPerson =新人[人物。计数];

Persons.Values.CopyTo(aPerson,0);


现在我可以访问人物项目,如aPerson [3] .name或

aPerson [3] .birthdate。


如何根据生日来对所有数组项进行排序?

这样生日的第一个名字可以在这里找到aPerson [0] .name

和aPerson [0] .birthdate。


谢谢!

Hello,

Persons is a hashtable which I convert to an array.

Person[] aPerson = new Person[Persons.Count];
Persons.Values.CopyTo( aPerson, 0 );

Now I can access the person items like aPerson[3].name or
aPerson[3].birthdate.

How can I sort all the array items based on the birthdate?
So that the first name with the birthdate can be found here aPerson[0].name
and aPerson[0].birthdate.

Thanks!

推荐答案

Arjen< bo ***** @ hotmail.com>写道:
Arjen <bo*****@hotmail.com> wrote:
人是一个哈希表,我将其转换为数组。

人[] aPerson =新人[Persons.Count];
Persons.Values。 CopyTo(aPerson,0);

现在我可以访问人物项目,如aPerson [3] .name或
aPerson [3] .birthdate。

如何我可以根据生日来对所有数组项进行排序吗?
这样可以在这里找到生日的第一个名字aPerson [0] .name
和aPerson [0] .birthdate。
Persons is a hashtable which I convert to an array.

Person[] aPerson = new Person[Persons.Count];
Persons.Values.CopyTo( aPerson, 0 );

Now I can access the person items like aPerson[3].name or
aPerson[3].birthdate.

How can I sort all the array items based on the birthdate?
So that the first name with the birthdate can be found here aPerson[0].name
and aPerson[0].birthdate.




将Array.Sort与IComparer一起使用,它可以按出生日期比较

人的实例。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



Use Array.Sort with an IComparer which is able to compare instances of
Person by birth date.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


好的,那是你的回答。

但我不能让它工作。


我也找到了一个文件如何排序哈希表...
http://msdn.microsoft.com/library/de...rp01212002.asp

但我不知道怎么做使用它。


你能给我一些示例代码吗?


谢谢!


Jon Skeet [C#MVP]" < SK *** @ pobox.com> schreef in bericht

新闻:MP ************************ @ msnews.microsoft.c om ...
Okay, that for your answer.
But I don''t get it to work.

I also found a document how to sort a hashtable...
http://msdn.microsoft.com/library/de...rp01212002.asp
But I don''t know how to work with it.

Can you give me a little sample code?

Thanks!

"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
Arjen< bo ***** @ hotmail.com>写道:
Arjen <bo*****@hotmail.com> wrote:
人是一个哈希表,我将其转换为数组。

人[] aPerson =新人[Persons.Count];
Persons.Values。 CopyTo(aPerson,0);

现在我可以访问人物项目,如aPerson [3] .name或
aPerson [3] .birthdate。

如何我可以根据生日来对所有数组项进行排序吗?
这样可以在这里找到生日的第一个名字
aPerson [0] .name和aPerson [0] .birthdate。
Persons is a hashtable which I convert to an array.

Person[] aPerson = new Person[Persons.Count];
Persons.Values.CopyTo( aPerson, 0 );

Now I can access the person items like aPerson[3].name or
aPerson[3].birthdate.

How can I sort all the array items based on the birthdate?
So that the first name with the birthdate can be found here aPerson[0].name and aPerson[0].birthdate.



将Array.Sort与IComparer一起使用,该IComparer能够按出生日期比较人员的实例。

-
Jon Skeet - < sk***@pobox.com>
http://www.pobox。 com / ~siget
如果回复小组,请不要给我发邮件



Use Array.Sort with an IComparer which is able to compare instances of
Person by birth date.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



这个:好的,那对你来说回答。

必须:...谢谢...


我得不到的是......

哈希table有对象...我怎样才能根据一个对象对hashtable进行排序

item?


谢谢!

Arjen



" Arjen" <博***** @ hotmail.com> schreef in bericht

新闻:bv ********** @ news1.tilbu1.nb.home.nl ...
This: Okay, that for your answer.
Must be: ...thanks...

What I don''t get is...
The hashtable has object... how can I sort the hashtable based on one object
item?

Thanks!
Arjen


"Arjen" <bo*****@hotmail.com> schreef in bericht
news:bv**********@news1.tilbu1.nb.home.nl...
好的,那对你而言回答。
但我不能让它工作。

我还找到了一个如何对散列表进行排序的文档...
http://msdn.microsoft.com /library/de...rp01212002.asp 但我不知道如何使用它。

你能给我一些示例代码吗?

Jon Skeet [C#MVP]" < SK *** @ pobox.com> schreef in bericht
新闻:MP ************************ @ msnews.microsoft.c om ...
Okay, that for your answer.
But I don''t get it to work.

I also found a document how to sort a hashtable...
http://msdn.microsoft.com/library/de...rp01212002.asp But I don''t know how to work with it.

Can you give me a little sample code?

Thanks!

"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
Arjen< bo ***** @ hotmail.com>写道:
Arjen <bo*****@hotmail.com> wrote:
人是一个哈希表,我将其转换为数组。

人[] aPerson =新人[Persons.Count];
Persons.Values。 CopyTo(aPerson,0);

现在我可以访问人物项目,如aPerson [3] .name或
aPerson [3] .birthdate。

如何我可以根据生日来对所有数组项进行排序吗?
这样可以在这里找到生日的第一个名字aPerson [0] .name和aPerson [0] .birthdate。
Persons is a hashtable which I convert to an array.

Person[] aPerson = new Person[Persons.Count];
Persons.Values.CopyTo( aPerson, 0 );

Now I can access the person items like aPerson[3].name or
aPerson[3].birthdate.

How can I sort all the array items based on the birthdate?
So that the first name with the birthdate can be found here aPerson[0].name and aPerson[0].birthdate.



使用带有IComparer的Array.Sort,它能够按出生日期比较
人员的实例。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件



Use Array.Sort with an IComparer which is able to compare instances of
Person by birth date.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




这篇关于如何对此数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆