p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=574)
-   -   Ex 15-2 (http://p2p.wrox.com/showthread.php?t=84513)

domino July 28th, 2011 12:18 AM

Ex 15-2
Hi Rod,
I am a novice programmer and I am trying to find out how I can do Ex 15-2 in C# Programming with Visual Studio 2010 24 hour trainer with both array and loop. I would love for anyone to solve this with a loop and array as i am having some difficulties in resolving this issue

domino July 28th, 2011 12:21 AM

Forgot to add here. The information I am specifically looking for is how I can enter the information about the 10 birthdates in listbox (as shown in Ex15-1 for one value) instead of hard coded values (as you have shown for Ex15-2) and I want to see it using both loops and arrays.

Rod Stephens July 28th, 2011 09:33 AM

A good question! Here's what I would do:

1. Get a birth date. Have the user enter a date in a TextBox and click a Go button.

2. Parse the date to create a Date variable. Use its Year, Month, and Day properties to get its year month and day.

3. Clear the ListBox. Then for (int i = 0; i <= 10; i++):

a. Create a new Date variable using the Year + i, Month, and Day.

b. Display the new Date and its DayOfWeek.ToString() in the ListBox.

I think you can do everything here except the loop with what you know by Lesson 15. Loops are covered in Lesson 19. (I suppose you could do this with a series of 11 nearly identical statements instead of using a loop but it would be poor code.)

Give that a try and let me know if you get stuck. If you want to see an example, email me and I'll send one to you.

All times are GMT -4. The time now is 08:45 AM.

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