Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8
This is the forum to discuss the Wrox book Professional C# 2008 by Christian Nagel, Bill Evjen, Jay Glynn, Morgan Skinner, Karli Watson; ISBN: 9780470191378
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 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 August 20th, 2009, 11:47 AM
Registered User
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enumerator problem

Hello,

This question relates to chapter 5 in the book. I'm getting an error when building the HelloCollection code.

'HelloCollection.Enumerator' does not contain a
constructor that takes '0' arguments

Code:
public class HelloCollection : IEnumerable {
			public IEnumerator GetEnumerator() {
				Enumerator enumerator = new Enumerator();
				return enumerator;
			}
			public class Enumerator : IEnumerator, IDisposable {
				private int state;
				private object current;
				
				public Enumerator(int state) {
					this.state = state;
				}

Clearly, the Enumerator constructor here does require one argument, and clearly the Enumerator is instantiated without passing in an argument. The book shows it this way, and I could not find a code example for this in the downloads. (The download has the HelloCollection that comes first in the book, the second version of it appears to be missing)

Should I be instantiating the Enumerator using a value of say 0?
  #2 (permalink)  
Old September 25th, 2009, 04:21 PM
Registered User
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I'm slowly making my way through the book. It'd be fantastic to know for sure if this is or is not an error in the book...

Also, the errata form has about 20 some fields to fill in. Come on, I'm not giving you my phone number (a required field ffs) just so that I can post an error in ***your*** book...

Here is possibly another error:

Page 814
string [] lines = new string[nLines];


Doesn't that need to use parenthesis instead of square brackets? new string(nLines);

Cheers
  #3 (permalink)  
Old December 7th, 2009, 02:35 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Thumbs up

you can write your Enumerator class like this:

Code:
public class Enumerator : IEnumerator, IDisposable 
{
   private int state;
   private object current;

   public Enumerator(int state) 
   {
      this.state = state;
   }

   public Enumerator() :this(0)
   {}
}
because you don't have defined parameterless constructor in your class, when you try to create a new object of this class in 'Enumerator enumerator = new Enumerator();' command you get and exception.
  #4 (permalink)  
Old December 7th, 2009, 04:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Quote:
Here is possibly another error:

Page 814
string [] lines = new string[nLines];


Doesn't that need to use parenthesis instead of square brackets? new string(nLines);
C# uses brackets.

Code:

// verbose
int[] a = newint[4];
for (int i = 0; i < a.Length; ++i)
{
   a[i] = (i + 1) * 2;
}
 
// compact
int[] b = newint[] { 2, 4, 6, 8 };
//ultra-compact
int[] c = { 2, 4, 6, 8 };
The Following User Says Thank You to Bob Bedell For This Useful Post:
irProject (December 18th, 2009)
 


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



All times are GMT -4. The time now is 09:18 PM.


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