Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2015, 01:59 PM
Registered User
 
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.
 
Old October 12th, 2015, 02:30 PM
Registered User
 
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.
 
Old October 12th, 2015, 07:08 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
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!)
 
Old August 9th, 2016, 09:30 AM
Registered User
 
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?
 
Old August 9th, 2016, 10:07 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
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!)





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 07:23 AM
Dynamic array of struct bobwrx C# 2 September 14th, 2006 06:12 AM





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