Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 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 December 22nd, 2012, 05:25 AM
Registered User
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Alternate Answer to Exercise 5 in Chapter 3

An alternative to the answer in the book that re-factors the code uses helper functions WriteNext and ConvertMyString:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exercise
{
class Program
{
static void Main(string[] args)
{
int firstValue, secondValue, thirdValue, fourthValue;
WriteNext ("1st");
firstValue = ConvertMyString();
WriteNext ("2nd");
secondValue = ConvertMyString();
WriteNext("3rd");
thirdValue = ConvertMyString();
WriteNext("4th");
fourthValue = ConvertMyString();
Console.WriteLine("The product of {0} {1} {2} and {3} is {4}.", firstValue, secondValue, thirdValue, fourthValue, firstValue * secondValue * thirdValue * fourthValue);
Console.ReadKey();
}

static int ConvertMyString()
{
int myInt;
myInt = Convert.ToInt32(Console.ReadLine());
return myInt;
}

static void WriteNext(string value)
{
Console.WriteLine("Enter {0} Value", value);
}
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 12, Exercise 5 Answer cree8uk BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 3 June 5th, 2010 02:33 PM
Wrong answer to Exercise 4 in Chapter3 lvehe BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 3 May 23rd, 2010 01:17 PM
Answer to Chapter 7, Exercise 4 samatron BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 1 January 16th, 2010 01:28 PM
chapter 10 - Alternate order walabok BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 March 19th, 2008 12:04 PM
The answer of Chapter 3,(5) wallhorse C# 2 June 30th, 2004 10:55 AM





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