Wrox Programmer Forums
|
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 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 July 22nd, 2013, 09:20 PM
Authorized User
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 17, Try It (again)

Ok, no it does not work.

I opened the solution provided in your source code download, and it works, but only because the items in the enumeration were manually entered into the Designer. (preferredMethodComboBox, Items Property, Collection).

If you go into the Designer and remove (or change) the Items that are listed in the Collection, the Build displays the modified Items, not the enumeration used in the code.

The enumeration is ignored, apparently.

not sure why.

Completely removing all Items from the Collection in the Designer causes the code to crash at:

preferredMethodComboBox.SelectedIndex = 0;

(again, the Build ignores the code and looks to the Collection in the Items Property)

You'll also notice that the code ignores the attempt to set the Indexes in the enumeration.

The way I finally got my attempt at the project to work was to go into the Designer and duplicate the items in the enumeration into the Items for the ComboBox.

The code does not work without doing that, so it's like double work!
 
Old July 22nd, 2013, 10:57 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Yes, the example didn't do that.

Don't do it if you don't want to. The idea is so the code can use the enumeration but as you point out it isn't complete.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 
Old July 23rd, 2013, 05:21 PM
Authorized User
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but still unsure of what an enumeration actually does.

Are they used that often?

I have two other books on C#, and they hardly mention enums at all.

Is it something you see often?
 
Old July 23rd, 2013, 05:41 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

You see them fairly often and you see them a lot in the .NET Framework. They do two things.

First they define a type. For example, if you need to let someone specify one of the values North, South, East, West, then you can define an enumeration named CompassDirection. Now I can declare a variable or parameter of that type and you have to use one of the allowed values. For example, if my TurnShip method takes a CompassDirection parameter, you cannot pass it the value 13.

Second, the define the values. In this example, the enumeration defines the values North, South, East, West.

To see why this is useful, suppose you don't have an enumeration. The TurnShip method could take a parameter that is a number (1 = North, 2 = South, etc.). But then you could pass the method the value 5 and confuse it.

Or TurnShip could take a string parameter ("North," "South," etc.). But then you could pass the method the value "down" and again confuse it.

The enumeration gives you strong type checking so Visual Studio can tell at design time whether the value you pass to TurnShip makes sense.
__________________
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
Lesson 17 Try It John S BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 7 June 14th, 2013 09:27 PM
Lesson 8 - Try It Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 February 12th, 2012 08:44 AM
Lesson 17 alawode BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 1 February 2nd, 2012 09:48 PM
Lesson 9 MTMike BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 3 November 3rd, 2011 01:51 PM
Lesson 8 sergeySE BOOK: Java Programming 24-Hour Trainer by Yakov Fain 1 June 29th, 2011 09:49 AM





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