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
| 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 Search this Thread Display Modes
  #1 (permalink)  
Old December 20th, 2011, 02:14 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch11 - Try it out Ex5 - Comparer Default

Would like to make sure I understand the concept behind the line of code in the class PersonComparerName:

Code:
public static IComparer Default = new PersonComparerName();
As I understand it - it is for "ease of use" in that it allows a short cut to instantiating an instance of IComparer (based on an instance of PersonComparerName via polymorphism) in this case for use in the line in program.cs:

Code:
list.Sort(PersonComparerName.Default);
One could also eliminate that line (in PersonComparerName above) and then either do something in program.cs like:

Code:
IComparer PersonCompareNameIComparer = new PersonComparerName();
list.Sort(PersonCompareNameIComparer);
or even :

Code:
list.Sort(new PersonComparerName());
(they both seem to work for me anyway).

Thanks for any additional clarification or insights on this.

stuartho
  #2 (permalink)  
Old December 29th, 2011, 05:51 PM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

if you use a "new PersonComparerName()" every time you're going to sort it that way you end up with multiple instances of PersonComparerName. If you are using "PersonComparerName.Default", only one instance of PersonComparerName is used.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Database comparer hema123 VB How-To 0 November 5th, 2008 02:43 AM
ch11 msxml3 code prob humayunlalzad BOOK: Beginning XML 3rd Edition 1 May 19th, 2007 02:38 AM
Problem using mail() from Ch11 nodster Beginning PHP 2 May 14th, 2007 08:44 AM
Ch11 Exerc 3 Appendix A problem VictorVictor BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 February 16th, 2006 03:41 PM



All times are GMT -4. The time now is 05:20 AM.


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