Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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
  #1 (permalink)  
Old July 20th, 2004, 02:07 PM
Authorized User
 
Join Date: Jul 2004
Location: Saint Peters, Missouri, USA.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual C# Exercises - Chapter 07

1. Maybe.
        If you intend code benchmarks in the beta release, then Trace
        makes sense but would necessitate clean up before final release.

2. ... At top of code
        using System.Diagnostics;

        ... In Main function
        int[] myArray = new int[500];
        int i;
        for (i = 0; i < 10000; i++)
        {
            Debug.Assert(i < 4999, "The test loop has reached 5000 iterations",
                "An error is pending - please step through debug");
            if (i == 4999)
            {
                Console.WriteLine("This array element {0} is going to break things!", myArray[1000]);
            }
        }

3. False, a finally code block always executes

4. ... At start of class
        enum orientation : byte
        {
            north = 1,
            south = 2,
            east = 3,
            west = 4
        }

        ... In Main function
        /* The checked function tests conversion of data types.
             * Assigning a value to "myByte" (as instructions suggested) precludes
             * conversion test to "orientation" since both are byte data types.
             * Following code tests string input conversion */
        try
        {
            orientation myDirection;
            Console.WriteLine("Enter a whole number to consider:");
            myDirection = checked((orientation)Convert.ToByte(Console.ReadLi ne()));
            Console.WriteLine("Here's your solution: {0}", (orientation)myDirection);
        }
        catch (OverflowException)
        {
            Console.WriteLine("The number you entered is out of bounds for the orientation data type");
        }
        catch (Exception e)
        {
            Console.WriteLine("An unexpected error resulted from your input: {0}", e.Message);
        }


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Visual C# Exercises - Chapter 15 seblake C# 1 September 17th, 2004 08:41 PM
Beginning Visual C# Exercises - Chapter 04 seblake C# 0 July 21st, 2004 09:21 AM
Beginning Visual C# Exercises - Chapter 03 seblake C# 1 July 19th, 2004 09:16 AM
Beginning Visual C# Exercises - Chapter 06 seblake C# 1 July 19th, 2004 09:15 AM





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