IT Community - Software Programming, Web Development and Technical Support

How to sort object array?

This is a discussion on How to sort object array? within the C# Programming forums, part of the Software Development category; I have created a class called "Books". Books[] bk = new Books[2]; bk[0] = new Books(); bk.Name = &...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:10 AM
raja raja is offline
D-Web Trainee
 
Join Date: May 2007
Posts: 34
raja is on a distinguished road
Question How to sort object array?

I have created a class called "Books".

Books[] bk = new Books[2];

bk[0] = new Books();
bk.Name = "Test";
bk[1] = new Books();
bk.Name = "Abs";


how to sort the object array bk?

Thanks in advance.
__________________
Raja. Myblog
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-03-2008, 07:39 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to sort object array?

you can use the

Array.Sort(Array, Array) function to Sort Arrays
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 09:08 AM
Anandavinayagam Anandavinayagam is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 131
Anandavinayagam is on a distinguished road
Default Re: How to sort object array?

some times it throws
"Specified IComparer threw an exception."
__________________
The MOSS
Master of Solution Service
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-03-2008, 09:09 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to sort object array?

oh...so implementation the IComparer interface....and add methods
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-14-2008, 09:52 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How to sort object array?

string[] files = System.IO.Directory.GetFiles();
NumericComparer ns = new NumericComparer();
Array.Sort(files, ns);
string[] dirs = System.IO.Directory.GetDirectories();
ns = new NumericComparer();
Array.Sort(dirs, ns);
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort Datatable oxygen C# Programming 2 04-22-2008 10:25 PM
Dif..sort();asort();ksort() Arun Flash Actionscript Programming 1 09-07-2007 08:14 AM
What’s the difference between the System.Array.CopyTo() and System.Array.Clone() ? Archer C# Programming 2 08-25-2007 03:00 AM
Object reference not set to an instance of an object for crystal reports in .net KiruthikaSambandam Database Support 1 08-03-2007 03:26 AM
How can you sort the elements of the array in descending order In C#. NET 2005? Archer C# Programming 1 07-24-2007 12:33 AM


All times are GMT -7. The time now is 01:18 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0