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: MCSD Certification Toolkit (Exam 70-483): Programming in C#
This is the forum to discuss the Wrox book MCSD Certification Toolkit (Exam 70-483): Programming in C# by Tiberiu Covaci, Rod Stephens, Vincent Varallo, Gerry O'Brien; ISBN: 978-1-118-61209-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C# 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 12th, 2015, 01:59 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default struct examples

I am going through the code in chapter 3. I cannot get the code in the book on page 68 regarding the structs to work. As soon as I start to key in anything following the initial struct, VS2015 shows an error saying that a } was expected. Not sure how to get around this.
Reply With Quote
  #2 (permalink)  
Old October 12th, 2015, 02:30 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wrong place

Found that the answer had to do with the code being in the wrong place in the class. Moved it outside the main mtehod and everything worked.
Reply With Quote
  #3 (permalink)  
Old October 12th, 2015, 07:08 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,153, Level: 23
Points: 3,153, Level: 23 Points: 3,153, Level: 23 Points: 3,153, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 643
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Glad you found the solution. Yes, you can declare structs (and classes) at the top level (directly inside the namespace) or inside a struct/class, but not inside a method.

Rod
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #4 (permalink)  
Old August 9th, 2016, 09:30 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I personally like to put classes in a separate file anyway, makes for cleaner code. I presume you can do that with structs too?
Reply With Quote
  #5 (permalink)  
Old August 9th, 2016, 10:07 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,153, Level: 23
Points: 3,153, Level: 23 Points: 3,153, Level: 23 Points: 3,153, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 643
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Yes you can. Authors sometimes put classes or structs in the same file just to make it easier to explain and to keep all of the code together, but many people use separate files for each piece of the program.

One easy way to make a struct in a separate file is to use Project > Add Class and then change the class keyword to struct.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
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

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
struct & class chinaNoob BOOK: Beginning Visual C# 2012 7 June 17th, 2014 05:46 AM
pointer to struct goscho C++ Programming 1 January 10th, 2008 06:23 AM
Dynamic array of struct bobwrx C# 2 September 14th, 2006 06:12 AM



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


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