Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 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 8th, 2009, 12:36 PM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code autogenerated by C# does not match that in book

I am finding that code in this book does not match that auto generated in MS Visual C# 2008.
For example on Page 201 the ArrayList example appears on a single page however the code is split between two pages, one headed Program.cs and another called Form1.cs.
Where ever I key the line
ArrayList names = new ArrayList();
it does not like it.
Can you advise where I have gone wrong?
Thanks
  #2 (permalink)  
Old December 8th, 2009, 01:55 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hello Martin.
What do you mean it doesn't "like it?" Are you getting a "Type or Namespace name 'ArrayList' could not be found" compiler error? If so, add the following using statement:

csharp Code:
using System.Collections;

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #3 (permalink)  
Old December 9th, 2009, 09:44 AM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Doug

Thanks for your reply.

By doesn't like it I mean that the Error List contains errors, these being:
1 A namespace does not directly contain members such as fields or methods.
2 Expected class, delegate, enum, interface or struct.

Adding the code you have provided does not remove this error.

Thanks

Martin
  #4 (permalink)  
Old December 9th, 2009, 10:11 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ahhh, it sounds like your code looks something like this:

csharp Code:
using System;
using System.Collections;
 
namespace Foo
{
   ArrayList names = new ArrayList();
   class Bar()
   {
   }
}

Which isn't legal. As the second error states only a class, delegate, enum, interface or struct is permited to be declared in a namespace. Move this declaration

csharp Code:
ArrayList names = new ArrayList();

into the class

csharp Code:
class Bar()
{
    ArrayList names = new ArrayList();   
}

This should clear up the error you are recieving.

hth
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
  #5 (permalink)  
Old December 12th, 2009, 11:27 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Array Lists

I just downloaded the code from the Wrox web site (I'm on vacation in FL) and the code compiled without error. However, if I took the array list definition and moved it outside the

publicclassfrmMain : Form

definition, then I get the errors that you mentioned. If you use the program template that I discuss on page 38 throughout the book, you won't have these issues. If you use the default (namespace) code generated by VS, these errors will occurs sometimes. Just use the template for the examples and you should have no problems.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
 


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
Customize autogenerated FormView templates? SpaceWokker ASP.NET 2.0 Basics 2 March 12th, 2007 11:19 AM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
how to email the autogenerated employeeid debjanib ASP.NET 1.0 and 1.1 Professional 7 July 27th, 2006 06:38 AM
Urgent!! code for no match in Subform based query smercer Access 3 September 10th, 2004 11:15 PM



All times are GMT -4. The time now is 02:22 AM.


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