Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 4th, 2012, 10:24 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 11 Sorting Question

In chapter 11, there is a Try It Out section about using Sorting with IComparable.

Below is the line that called the sorting method
Code:
Console.WriteLine("People sorted with default comparer (by age):");
list.Sort();
When I debugged it, that line goes to CompareTo method just like the book explained, but I don't understand how the CompareTo method ended up sorting the ArrayList. I just do not see how this happens even after I debug the code. Can anyone explain why the code below works to sort the ArrayList? I do not see that the code change the position of the items in the ArrayList.

Code:
public int CompareTo(object obj)
    {
      if (obj is Person)
      {
        Person otherPerson = obj as Person;
        return this.Age - otherPerson.Age;
      }
      else
      {
        throw new ArgumentException("Object to compare to is not a Person object.");
      } 
    }
 


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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 11 Question tixrus BOOK: Beginning JavaScript and CSS Development with jQuery 0 April 11th, 2010 06:23 PM
Chapter 11: SQL Server connection (General question) StamPita BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 January 2nd, 2010 02:02 PM
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM
A simple Sorting question bonekrusher XSLT 2 November 25th, 2007 09:40 AM
Quick Question for Author of Chapter 11 Wullie BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 July 16th, 2006 07:54 PM



All times are GMT -4. The time now is 07:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.